Spaces:
Runtime error
Runtime error
Commit
·
84aa20e
1
Parent(s):
1610379
Update app.py
Browse files
app.py
CHANGED
@@ -74,14 +74,14 @@ def load_index(index_path):
|
|
74 |
"""Load FAISS index once and cache it"""
|
75 |
return faiss.read_index(index_path)
|
76 |
|
77 |
-
def distance_to_similarity(
|
78 |
"""Convert distance to similarity"""
|
79 |
-
for ii in range(len(
|
80 |
-
contribs =
|
81 |
contribs = contribs / temp
|
82 |
sum_contribs = np.exp(contribs).sum()
|
83 |
-
|
84 |
-
return
|
85 |
|
86 |
def calculate_rewards(subscription, num_generations, author_share, ro_share, num_users_k, similarities, num_authors=1800):
|
87 |
"""Calculate rewards based on user inputs and similarities"""
|
@@ -99,12 +99,6 @@ def calculate_rewards(subscription, num_generations, author_share, ro_share, num
|
|
99 |
author_month_reward = (authors_monthly_revenue / num_authors) * attribution_bonus
|
100 |
ro_month_reward = author_month_reward / (author_share / 100) * (ro_share / 100)
|
101 |
|
102 |
-
try:
|
103 |
-
sim_value = float(sim.item()) if hasattr(sim, "item") else float(sim)
|
104 |
-
except Exception as e:
|
105 |
-
print("Erreur de conversion de sim:", e)
|
106 |
-
sim_value = 0.0 # valeur par défaut en cas d'erreur
|
107 |
-
|
108 |
rewards.append({
|
109 |
'paid_per_month': f"{subscription:.0f}€",
|
110 |
'attribution': f"{sim * 100:.0f}%",
|
@@ -179,15 +173,13 @@ def select_preset(preset_id):
|
|
179 |
#image2 = load_image(PRESET_IMAGES[2])
|
180 |
|
181 |
# Extraire les features
|
182 |
-
image1 = Image.open("static/1.webp")
|
183 |
-
image2 = Image.open("static/2.webp")
|
184 |
-
features1 = get_ft(model, image1)
|
185 |
-
features2 = get_ft(model, image2)
|
186 |
|
187 |
# Calculer la distance euclidienne
|
188 |
-
distances = np.linalg.norm(features1 - features2)
|
189 |
-
|
190 |
-
#print(f"Distance euclidienne entre l'image 1 et l'image 2 : {distances}")
|
191 |
|
192 |
# Collect valid results first
|
193 |
valid_results = []
|
|
|
74 |
"""Load FAISS index once and cache it"""
|
75 |
return faiss.read_index(index_path)
|
76 |
|
77 |
+
def distance_to_similarity(distances, temp=1e-4):
|
78 |
"""Convert distance to similarity"""
|
79 |
+
for ii in range(len(distances)):
|
80 |
+
contribs = distances[ii].max() - distances[ii]
|
81 |
contribs = contribs / temp
|
82 |
sum_contribs = np.exp(contribs).sum()
|
83 |
+
distances[ii] = np.exp(contribs) / sum_contribs
|
84 |
+
return distances
|
85 |
|
86 |
def calculate_rewards(subscription, num_generations, author_share, ro_share, num_users_k, similarities, num_authors=1800):
|
87 |
"""Calculate rewards based on user inputs and similarities"""
|
|
|
99 |
author_month_reward = (authors_monthly_revenue / num_authors) * attribution_bonus
|
100 |
ro_month_reward = author_month_reward / (author_share / 100) * (ro_share / 100)
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
rewards.append({
|
103 |
'paid_per_month': f"{subscription:.0f}€",
|
104 |
'attribution': f"{sim * 100:.0f}%",
|
|
|
173 |
#image2 = load_image(PRESET_IMAGES[2])
|
174 |
|
175 |
# Extraire les features
|
176 |
+
#image1 = Image.open("static/1.webp")
|
177 |
+
#image2 = Image.open("static/2.webp")
|
178 |
+
#features1 = get_ft(model, image1)
|
179 |
+
#features2 = get_ft(model, image2)
|
180 |
|
181 |
# Calculer la distance euclidienne
|
182 |
+
#distances = np.linalg.norm(features1 - features2)
|
|
|
|
|
183 |
|
184 |
# Collect valid results first
|
185 |
valid_results = []
|