Update app.py
Browse files
app.py
CHANGED
@@ -291,22 +291,22 @@ def update_leaderboard_pro(results):
|
|
291 |
try:
|
292 |
# Update the local leaderboard file
|
293 |
new_entry_df = pd.DataFrame([new_entry])
|
294 |
-
file_exists = os.path.exists(
|
295 |
|
296 |
new_entry_df.to_csv(
|
297 |
-
|
298 |
mode='a', # Append mode
|
299 |
index=False,
|
300 |
header=not file_exists # Write header only if the file is new
|
301 |
)
|
302 |
-
print(f"Leaderboard updated successfully at {
|
303 |
|
304 |
# Push the updated file to the Hugging Face repository using HTTP API
|
305 |
api = HfApi()
|
306 |
token = HfFolder.get_token()
|
307 |
|
308 |
api.upload_file(
|
309 |
-
path_or_fileobj=
|
310 |
path_in_repo="leaderboardPro.csv",
|
311 |
repo_id="SondosMB/Mobile-MMLU", # Your Space repository
|
312 |
repo_type="space",
|
@@ -343,6 +343,19 @@ def load_leaderboard():
|
|
343 |
|
344 |
})
|
345 |
return pd.read_csv(LEADERBOARD_FILE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
|
347 |
# def evaluate_predictions(prediction_file, model_name, add_to_leaderboard):
|
348 |
# try:
|
@@ -486,7 +499,7 @@ def evaluate_predictions_pro(prediction_file, model_name,Team_name ,add_to_leade
|
|
486 |
missing_columns = [col for col in required_columns if col not in predictions_df.columns]
|
487 |
if missing_columns:
|
488 |
return (f"Error: Missing required columns in prediction file: {', '.join(missing_columns)}.",
|
489 |
-
|
490 |
|
491 |
# Validate 'Answer' column in ground truth file
|
492 |
if 'Answer' not in ground_truth_df.columns:
|
@@ -1056,14 +1069,14 @@ with gr.Blocks(css=css_tech_theme) as demo:
|
|
1056 |
)
|
1057 |
with gr.TabItem("🏅 Leaderboard-pro"):
|
1058 |
leaderboard_table = gr.Dataframe(
|
1059 |
-
value=
|
1060 |
label="Leaderboard",
|
1061 |
interactive=False,
|
1062 |
wrap=True,
|
1063 |
)
|
1064 |
refresh_button = gr.Button("Refresh Leaderboard")
|
1065 |
refresh_button.click(
|
1066 |
-
lambda:
|
1067 |
inputs=[],
|
1068 |
outputs=[leaderboard_table],
|
1069 |
)
|
|
|
291 |
try:
|
292 |
# Update the local leaderboard file
|
293 |
new_entry_df = pd.DataFrame([new_entry])
|
294 |
+
file_exists = os.path.exists(LEADERBOARD_FILE_pro)
|
295 |
|
296 |
new_entry_df.to_csv(
|
297 |
+
LEADERBOARD_FILE_pro,
|
298 |
mode='a', # Append mode
|
299 |
index=False,
|
300 |
header=not file_exists # Write header only if the file is new
|
301 |
)
|
302 |
+
print(f"Leaderboard updated successfully at {LEADERBOARD_FILE_pro}")
|
303 |
|
304 |
# Push the updated file to the Hugging Face repository using HTTP API
|
305 |
api = HfApi()
|
306 |
token = HfFolder.get_token()
|
307 |
|
308 |
api.upload_file(
|
309 |
+
path_or_fileobj=LEADERBOARD_FILE_pro,
|
310 |
path_in_repo="leaderboardPro.csv",
|
311 |
repo_id="SondosMB/Mobile-MMLU", # Your Space repository
|
312 |
repo_type="space",
|
|
|
343 |
|
344 |
})
|
345 |
return pd.read_csv(LEADERBOARD_FILE)
|
346 |
+
|
347 |
+
def load_leaderboard_pro():
|
348 |
+
if not os.path.exists(LEADERBOARD_FILE_pro) or os.stat(LEADERBOARD_FILE_pro).st_size == 0:
|
349 |
+
return pd.DataFrame({
|
350 |
+
"Model Name": [],
|
351 |
+
"Overall Accuracy": [],
|
352 |
+
"Correct Predictions": [],
|
353 |
+
"Total Questions": [],
|
354 |
+
"Timestamp": [],
|
355 |
+
"Team Name": [],
|
356 |
+
|
357 |
+
})
|
358 |
+
return pd.read_csv(LEADERBOARD_FILE_pro)
|
359 |
|
360 |
# def evaluate_predictions(prediction_file, model_name, add_to_leaderboard):
|
361 |
# try:
|
|
|
499 |
missing_columns = [col for col in required_columns if col not in predictions_df.columns]
|
500 |
if missing_columns:
|
501 |
return (f"Error: Missing required columns in prediction file: {', '.join(missing_columns)}.",
|
502 |
+
load_leaderboard_pro())
|
503 |
|
504 |
# Validate 'Answer' column in ground truth file
|
505 |
if 'Answer' not in ground_truth_df.columns:
|
|
|
1069 |
)
|
1070 |
with gr.TabItem("🏅 Leaderboard-pro"):
|
1071 |
leaderboard_table = gr.Dataframe(
|
1072 |
+
value=load_leaderboard_pro(),
|
1073 |
label="Leaderboard",
|
1074 |
interactive=False,
|
1075 |
wrap=True,
|
1076 |
)
|
1077 |
refresh_button = gr.Button("Refresh Leaderboard")
|
1078 |
refresh_button.click(
|
1079 |
+
lambda: load_leaderboard_pro(),
|
1080 |
inputs=[],
|
1081 |
outputs=[leaderboard_table],
|
1082 |
)
|