Update app.py
Browse files
app.py
CHANGED
@@ -169,8 +169,7 @@ import os
|
|
169 |
import re
|
170 |
from datetime import datetime
|
171 |
from huggingface_hub import hf_hub_download
|
172 |
-
|
173 |
-
|
174 |
|
175 |
LEADERBOARD_FILE = "leaderboard.csv"
|
176 |
GROUND_TRUTH_FILE = "ground_truth.csv"
|
@@ -204,7 +203,11 @@ def clean_answer(answer):
|
|
204 |
clean = re.sub(r'[^A-Da-d]', '', answer)
|
205 |
return clean[0].upper() if clean else None
|
206 |
|
|
|
207 |
def update_leaderboard(results):
|
|
|
|
|
|
|
208 |
new_entry = {
|
209 |
"Model Name": results['model_name'],
|
210 |
"Overall Accuracy": round(results['overall_accuracy'] * 100, 2),
|
@@ -215,28 +218,33 @@ def update_leaderboard(results):
|
|
215 |
}
|
216 |
|
217 |
try:
|
|
|
218 |
new_entry_df = pd.DataFrame([new_entry])
|
|
|
|
|
219 |
new_entry_df.to_csv(
|
220 |
LEADERBOARD_FILE,
|
221 |
mode='a', # Append mode
|
222 |
index=False,
|
223 |
-
header=not
|
224 |
)
|
225 |
-
print("Leaderboard
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
)
|
232 |
-
repo.git_add(LEADERBOARD_FILE)
|
233 |
-
repo.git_commit(f"Update leaderboard: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
234 |
-
repo.git_push()
|
235 |
print("Leaderboard changes pushed to Hugging Face repository.")
|
236 |
-
|
237 |
except Exception as e:
|
238 |
-
print(f"Error updating leaderboard file: {e}")
|
239 |
-
|
240 |
|
241 |
|
242 |
|
|
|
169 |
import re
|
170 |
from datetime import datetime
|
171 |
from huggingface_hub import hf_hub_download
|
172 |
+
ffrom huggingface_hub import HfApi, HfFolder
|
|
|
173 |
|
174 |
LEADERBOARD_FILE = "leaderboard.csv"
|
175 |
GROUND_TRUTH_FILE = "ground_truth.csv"
|
|
|
203 |
clean = re.sub(r'[^A-Da-d]', '', answer)
|
204 |
return clean[0].upper() if clean else None
|
205 |
|
206 |
+
|
207 |
def update_leaderboard(results):
|
208 |
+
"""
|
209 |
+
Append new submission results to the leaderboard file and push updates to the Hugging Face repository.
|
210 |
+
"""
|
211 |
new_entry = {
|
212 |
"Model Name": results['model_name'],
|
213 |
"Overall Accuracy": round(results['overall_accuracy'] * 100, 2),
|
|
|
218 |
}
|
219 |
|
220 |
try:
|
221 |
+
# Update the local leaderboard file
|
222 |
new_entry_df = pd.DataFrame([new_entry])
|
223 |
+
file_exists = os.path.exists(LEADERBOARD_FILE)
|
224 |
+
|
225 |
new_entry_df.to_csv(
|
226 |
LEADERBOARD_FILE,
|
227 |
mode='a', # Append mode
|
228 |
index=False,
|
229 |
+
header=not file_exists # Write header only if the file is new
|
230 |
)
|
231 |
+
print(f"Leaderboard updated successfully at {LEADERBOARD_FILE}")
|
232 |
+
|
233 |
+
# Push the updated file to the Hugging Face repository using HTTP API
|
234 |
+
api = HfApi()
|
235 |
+
token = HfFolder.get_token()
|
236 |
+
|
237 |
+
api.upload_file(
|
238 |
+
path_or_fileobj=LEADERBOARD_FILE,
|
239 |
+
path_in_repo="leaderboard.csv",
|
240 |
+
repo_id="SondosMB/ss", # Your Space repository
|
241 |
+
repo_type="space",
|
242 |
+
token=token
|
243 |
)
|
|
|
|
|
|
|
244 |
print("Leaderboard changes pushed to Hugging Face repository.")
|
245 |
+
|
246 |
except Exception as e:
|
247 |
+
print(f"Error updating leaderboard file: {e}")
|
|
|
248 |
|
249 |
|
250 |
|