vicliv commited on
Commit
14b33a7
·
1 Parent(s): 32089d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -48,7 +48,26 @@ def load_leaderboard():
48
  print(f"Failed to load leaderboard from HF Hub: {e}")
49
  return {}
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  leaderboard_scores = load_leaderboard()
 
52
 
53
  def save_leaderboard():
54
  try:
@@ -176,8 +195,8 @@ def detect_with_model(image: Image.Image, prompt: str, username: str, model_name
176
  image.save(image_path)
177
 
178
  csv_path = os.path.join("test", "leaderboard_entries.csv")
179
- header = "file_name,prompt,label,model,split,prediction,user,timestamp\n"
180
- csv_line = f"test/{type_image}/{image_filename},\"{prompt}\",{type_image},{model_name.lower()},test,{prediction.lower()},{username},{datetime.now().isoformat()}\n"
181
  try:
182
  file_exists = os.path.exists(csv_path)
183
  with open(csv_path, "a", encoding="utf-8") as f:
 
48
  print(f"Failed to load leaderboard from HF Hub: {e}")
49
  return {}
50
 
51
+ def load_entries():
52
+ try:
53
+ # grab the CSV of all past plays
54
+ csv_path = hf_hub_download(
55
+ repo_id=HUB_REPO_ID,
56
+ repo_type="dataset",
57
+ filename="test/leaderboard_entries.csv",
58
+ token=HF_TOKEN
59
+ )
60
+ df = pd.read_csv(csv_path)
61
+
62
+ return df
63
+
64
+ except Exception as e:
65
+ print(f"Failed to load leaderboard from HF Hub: {e}")
66
+ # if anything goes wrong, fall back to empty
67
+ return pd.Dataframe(columns=["file_name","prompt","label","model","split","prediction","user","timestamp"])
68
+
69
  leaderboard_scores = load_leaderboard()
70
+ leaderboard_entries = load_entries()
71
 
72
  def save_leaderboard():
73
  try:
 
195
  image.save(image_path)
196
 
197
  csv_path = os.path.join("test", "leaderboard_entries.csv")
198
+ df.loc[len(df)] = [f"test/{type_image}/{image_filename}", prompt, type_image, model_name.lower(), "test", prediction.lower(), username, datetime.now().isoformat()]
199
+ df.to_csv(csv_path, index=False)
200
  try:
201
  file_exists = os.path.exists(csv_path)
202
  with open(csv_path, "a", encoding="utf-8") as f: