Spaces:
Runtime error
Runtime error
Commit
·
cedfc32
1
Parent(s):
ff9ba81
Update app.py
Browse files
app.py
CHANGED
@@ -80,20 +80,25 @@ def distance_to_similarity(distances, temp=1e-4):
|
|
80 |
distances[ii] = np.exp(contribs) / sum_contribs
|
81 |
return distances
|
82 |
|
|
|
|
|
83 |
def calculate_rewards(subscription, num_generations, author_share, ro_share, num_users_k, similarities, num_authors=1800):
|
84 |
"""Calculate rewards based on user inputs and similarities"""
|
85 |
num_users = num_users_k * 1000
|
86 |
-
|
87 |
-
# Extraire les features
|
88 |
-
image1 = Image.open("static/1.webp")
|
89 |
-
image2 = Image.open("static/2.webp")
|
90 |
-
features1 = get_ft(model, image1)
|
91 |
-
features2 = get_ft(model, image2)
|
92 |
-
|
93 |
-
# Calculer la distance euclidienne
|
94 |
-
euclid = np.linalg.norm(features1 - features2)
|
95 |
-
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
# Monthly revenue allocated to authors
|
98 |
authors_monthly_revenue = subscription * num_users * (author_share / 100)
|
99 |
|
@@ -118,16 +123,10 @@ def calculate_rewards(subscription, num_generations, author_share, ro_share, num
|
|
118 |
'author_month_reward': f"{author_month_reward:.0f}€",
|
119 |
'ro_month_reward': f"{ro_month_reward:.0f}€",
|
120 |
'raw_similarity': euclid
|
121 |
-
# 'paid_per_month': f"{subscription:.0f}€",
|
122 |
-
# 'paid_per_gen': f"{paid_per_gen:.2f}€",
|
123 |
-
# 'aro_share': f"{aro_share:.2f}c€",
|
124 |
-
# 'attribution': f"{sim*100:.0f}%",
|
125 |
-
# 'training_data_reward': f"{training_data_reward:.2f}c€",
|
126 |
-
# 'author_month_reward': f"{author_month_reward:.0f}€",
|
127 |
-
# 'ro_month_reward': f"{ro_month_reward:.0f}€"
|
128 |
})
|
129 |
return rewards
|
130 |
|
|
|
131 |
# Global variables for model and index
|
132 |
model = None
|
133 |
index = None
|
|
|
80 |
distances[ii] = np.exp(contribs) / sum_contribs
|
81 |
return distances
|
82 |
|
83 |
+
import os
|
84 |
+
|
85 |
def calculate_rewards(subscription, num_generations, author_share, ro_share, num_users_k, similarities, num_authors=1800):
|
86 |
"""Calculate rewards based on user inputs and similarities"""
|
87 |
num_users = num_users_k * 1000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
+
try:
|
90 |
+
if os.path.exists("static/1.webp") and os.path.exists("static/2.webp"):
|
91 |
+
image1 = Image.open("static/1.webp")
|
92 |
+
image2 = Image.open("static/2.webp")
|
93 |
+
features1 = get_ft(model, image1)
|
94 |
+
features2 = get_ft(model, image2)
|
95 |
+
euclid = np.linalg.norm(features1 - features2)
|
96 |
+
else:
|
97 |
+
euclid = 0 # pas d'image, euclidienne à 0
|
98 |
+
except Exception as e:
|
99 |
+
print(f"Erreur lors du chargement des images : {e}")
|
100 |
+
euclid = 0 # sécurité
|
101 |
+
|
102 |
# Monthly revenue allocated to authors
|
103 |
authors_monthly_revenue = subscription * num_users * (author_share / 100)
|
104 |
|
|
|
123 |
'author_month_reward': f"{author_month_reward:.0f}€",
|
124 |
'ro_month_reward': f"{ro_month_reward:.0f}€",
|
125 |
'raw_similarity': euclid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
})
|
127 |
return rewards
|
128 |
|
129 |
+
|
130 |
# Global variables for model and index
|
131 |
model = None
|
132 |
index = None
|