Spaces:
Runtime error
Runtime error
Commit
·
77e13dc
1
Parent(s):
9bf9553
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,11 @@
|
|
2 |
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
-
import io
|
6 |
-
import faiss
|
7 |
|
8 |
-
import requests
|
9 |
-
import torch
|
10 |
|
11 |
from request import get_ft, get_topk #get_ft extrait les vecteurs, get_topk trouve les k plus proches voisins
|
12 |
from flickrapi import FlickrAPI
|
@@ -14,7 +14,7 @@ from flickrapi import FlickrAPI
|
|
14 |
from flask import Flask, request, render_template, jsonify, send_from_directory
|
15 |
app = Flask(__name__)
|
16 |
|
17 |
-
PRESET_IMAGES = {
|
18 |
1: "static/1.webp",
|
19 |
2: "static/2.webp",
|
20 |
3: "static/3.webp"
|
@@ -26,8 +26,7 @@ FLICKR_API_SECRET = '4d0e8ce6734f4b3f'
|
|
26 |
flickr = FlickrAPI(FLICKR_API_KEY, FLICKR_API_SECRET, format='parsed-json', store_token=False)
|
27 |
|
28 |
def get_photo_id(url):
|
29 |
-
"""Extract photo ID from Flickr URL"""
|
30 |
-
"""ex. get_photo_id(https://exemple.com/images/photo_chat_001.jpg)= photo"""
|
31 |
try:
|
32 |
return url.split('/')[-1].split('_')[0]
|
33 |
except:
|
@@ -214,8 +213,8 @@ def process_image():
|
|
214 |
return jsonify({'error': 'No image provided'}), 400
|
215 |
|
216 |
try:
|
217 |
-
image_file = request.files['image']
|
218 |
-
image = Image.open(io.BytesIO(image_file.read())).convert('RGB')
|
219 |
|
220 |
# Use default parameters if none provided
|
221 |
params = DEFAULT_PARAMS.copy()
|
@@ -231,8 +230,8 @@ def process_image():
|
|
231 |
})
|
232 |
|
233 |
# Process image
|
234 |
-
features = get_ft(model, image)
|
235 |
-
distances, indices = get_topk(index, features, topk=params['num_neighbors'])
|
236 |
|
237 |
# Collect valid results first
|
238 |
valid_results = []
|
|
|
2 |
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
+
import io #manipule des images téléchargées via une URL ou une API
|
6 |
+
import faiss #librairie pour la recherche de similarité dans des vecteurs
|
7 |
|
8 |
+
import requests #télécharge des images et récupére une image depuis une URL
|
9 |
+
import torch #modèles de machine learning pour extraire les features d’images (vecteurs)
|
10 |
|
11 |
from request import get_ft, get_topk #get_ft extrait les vecteurs, get_topk trouve les k plus proches voisins
|
12 |
from flickrapi import FlickrAPI
|
|
|
14 |
from flask import Flask, request, render_template, jsonify, send_from_directory
|
15 |
app = Flask(__name__)
|
16 |
|
17 |
+
PRESET_IMAGES = { #les images présélectionnées sont rangées sous /static
|
18 |
1: "static/1.webp",
|
19 |
2: "static/2.webp",
|
20 |
3: "static/3.webp"
|
|
|
26 |
flickr = FlickrAPI(FLICKR_API_KEY, FLICKR_API_SECRET, format='parsed-json', store_token=False)
|
27 |
|
28 |
def get_photo_id(url):
|
29 |
+
"""Extract photo ID from Flickr URL""" #ex. get_photo_id(https://exemple.com/images/photo_chat_001.jpg)= photo
|
|
|
30 |
try:
|
31 |
return url.split('/')[-1].split('_')[0]
|
32 |
except:
|
|
|
213 |
return jsonify({'error': 'No image provided'}), 400
|
214 |
|
215 |
try:
|
216 |
+
image_file = request.files['image'] #attend un fichier image transmis par l'utilisateur
|
217 |
+
image = Image.open(io.BytesIO(image_file.read())).convert('RGB') #convertit l'image en RGB
|
218 |
|
219 |
# Use default parameters if none provided
|
220 |
params = DEFAULT_PARAMS.copy()
|
|
|
230 |
})
|
231 |
|
232 |
# Process image
|
233 |
+
features = get_ft(model, image) ######## extrait le vecteur de l'image
|
234 |
+
distances, indices = get_topk(index, features, topk=params['num_neighbors']) ######## extrait les distances avec les premiers voisins
|
235 |
|
236 |
# Collect valid results first
|
237 |
valid_results = []
|