TheFrenchDemos commited on
Commit
567b5f3
·
1 Parent(s): 4f5a1cf

Update app.py

Browse files

la version précédente provoque encore un "runtime error"
Remplacement complet de calculate_rewards

Files changed (1) hide show
  1. app.py +12 -30
app.py CHANGED
@@ -82,51 +82,33 @@ def distance_to_similarity(distances, temp=1e-4):
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, image1) #temporaire : remettre image2
95
  euclid = float(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
-
105
- rewards = []
106
- ###for sim in similarities[0]:
107
- # Attribution bonus based on similarity score and number of neighbors
108
- ###attribution_bonus = sim * len(similarities[0])
109
-
110
- # Calculate monthly rewards
111
- ###author_month_reward = (authors_monthly_revenue / num_authors) * attribution_bonus
112
- ###ro_month_reward = author_month_reward / (author_share / 100) * (ro_share / 100)
113
-
114
- ###try:
115
- ### sim_value = float(sim.item()) if hasattr(sim, "item") else float(sim)
116
- ###except Exception as e:
117
- ### print("Erreur de conversion de sim:", e)
118
- ### sim_value = 0.0 # valeur par défaut en cas d'erreur
119
-
120
- rewards.append({
121
- ### 'paid_per_month': f"{subscription:.0f}€",
122
- ### 'attribution': f"{sim*100:.0f}%",
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
 
82
 
83
  import os
84
 
85
+ import os
86
+ from PIL import Image
87
+ import numpy as np
88
+
89
  def calculate_rewards(subscription, num_generations, author_share, ro_share, num_users_k, similarities, num_authors=1800):
90
+ """Calculate raw similarity (distance) between two static images"""
 
91
 
92
  try:
93
  if os.path.exists("static/1.webp") and os.path.exists("static/2.webp"):
94
  image1 = Image.open("static/1.webp")
95
  image2 = Image.open("static/2.webp")
96
  features1 = get_ft(model, image1)
97
+ features2 = get_ft(model, image1) # temporaire : remettre image2
98
  euclid = float(np.linalg.norm(features1 - features2))
99
  else:
100
+ euclid = 0.0
101
  except Exception as e:
102
  print(f"Erreur lors du chargement des images : {e}")
103
+ euclid = 0.0
104
 
105
+ rewards = [{
106
+ 'raw_similarity': euclid
107
+ }]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  return rewards
109
 
110
 
111
+
112
  # Global variables for model and index
113
  model = None
114
  index = None