Spaces:
Runtime error
Runtime error
Commit
·
b556cc9
1
Parent(s):
34d6165
Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,7 @@ flickr = FlickrAPI(FLICKR_API_KEY, FLICKR_API_SECRET, format='parsed-json', stor
|
|
27 |
|
28 |
def get_photo_id(url):
|
29 |
"""Extract photo ID from Flickr URL"""
|
|
|
30 |
try:
|
31 |
return url.split('/')[-1].split('_')[0]
|
32 |
except:
|
@@ -89,7 +90,7 @@ def calculate_rewards(subscription, num_generations, author_share, ro_share, num
|
|
89 |
|
90 |
rewards = []
|
91 |
for sim in similarities[0]:
|
92 |
-
# Attribution bonus based on similarity score and number of neighbors
|
93 |
attribution_bonus = sim * len(similarities[0])
|
94 |
|
95 |
# Calculate monthly rewards
|
@@ -117,11 +118,11 @@ index = None
|
|
117 |
urls = None
|
118 |
|
119 |
def init_model():
|
120 |
-
global model, index, urls
|
121 |
-
model = load_model()
|
122 |
-
index = load_index("data/openimages_index.bin")
|
123 |
-
with open("data/openimages_urls.txt", "r") as f
|
124 |
-
urls = f.readlines()
|
125 |
|
126 |
@app.route('/')
|
127 |
def home():
|
@@ -143,19 +144,23 @@ DEFAULT_PARAMS = {
|
|
143 |
|
144 |
@app.route('/select_preset/<int:preset_id>')
|
145 |
def select_preset(preset_id):
|
146 |
-
if preset_id not in PRESET_IMAGES:
|
147 |
return jsonify({'error': 'Invalid preset ID'}), 400
|
148 |
|
149 |
try:
|
150 |
-
image_path = PRESET_IMAGES[preset_id]
|
151 |
image = Image.open(image_path).convert('RGB')
|
152 |
|
153 |
# Use default parameters for presets
|
154 |
params = DEFAULT_PARAMS.copy()
|
155 |
|
156 |
# Get features and search
|
157 |
-
features = get_ft(model, image)
|
158 |
distances, indices = get_topk(index, features, topk=params['num_neighbors'])
|
|
|
|
|
|
|
|
|
159 |
|
160 |
# Collect valid results first
|
161 |
valid_results = []
|
|
|
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:
|
|
|
90 |
|
91 |
rewards = []
|
92 |
for sim in similarities[0]:
|
93 |
+
# Attribution bonus based on similarity score (sim) and number of neighbors (len)
|
94 |
attribution_bonus = sim * len(similarities[0])
|
95 |
|
96 |
# Calculate monthly rewards
|
|
|
118 |
urls = None
|
119 |
|
120 |
def init_model():
|
121 |
+
global model, index, urls #variables du script, et non de la seule fonction
|
122 |
+
model = load_model() #model charge DinoV2
|
123 |
+
index = load_index("data/openimages_index.bin") #index charge l'index binaire des vecteurs
|
124 |
+
with open("data/openimages_urls.txt", "r") as f:#ouvre le fichier texte des URLs
|
125 |
+
urls = f.readlines() #lit toutes les URLs
|
126 |
|
127 |
@app.route('/')
|
128 |
def home():
|
|
|
144 |
|
145 |
@app.route('/select_preset/<int:preset_id>')
|
146 |
def select_preset(preset_id):
|
147 |
+
if preset_id not in PRESET_IMAGES: #vérification de l'existence de preset_id dans le dictionnaire
|
148 |
return jsonify({'error': 'Invalid preset ID'}), 400
|
149 |
|
150 |
try:
|
151 |
+
image_path = PRESET_IMAGES[preset_id] #récupère le chemin du fichier image
|
152 |
image = Image.open(image_path).convert('RGB')
|
153 |
|
154 |
# Use default parameters for presets
|
155 |
params = DEFAULT_PARAMS.copy()
|
156 |
|
157 |
# Get features and search
|
158 |
+
features = get_ft(model, image) #extrait les features, soit le vecteur représentant l’image
|
159 |
distances, indices = get_topk(index, features, topk=params['num_neighbors'])
|
160 |
+
#utilise l’index pour trouver les k voisins de l’image
|
161 |
+
#retourne
|
162 |
+
# - distances avec les voisins
|
163 |
+
# - indices : les positions (dans l'index) des voisins
|
164 |
|
165 |
# Collect valid results first
|
166 |
valid_results = []
|