Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Shiyu Zhao
commited on
Commit
•
b554584
1
Parent(s):
29e4883
Update space
Browse files
app.py
CHANGED
@@ -122,7 +122,7 @@ class SubmissionForum:
|
|
122 |
|
123 |
# Initialize storage once at startup
|
124 |
try:
|
125 |
-
REPO_ID = "snap-stanford/stark-leaderboard"
|
126 |
hub_storage = HubStorage(REPO_ID)
|
127 |
forum = SubmissionForum(hub_storage=hub_storage)
|
128 |
except Exception as e:
|
@@ -797,39 +797,26 @@ def process_submission(
|
|
797 |
folder_name = f"{sanitize_name(method_name)}_{sanitize_name(team_name)}"
|
798 |
|
799 |
# Process CSV file
|
800 |
-
|
801 |
if isinstance(csv_file, str):
|
802 |
-
|
|
|
|
|
|
|
|
|
803 |
else:
|
804 |
-
|
805 |
-
temp_files.append(temp_csv_path)
|
806 |
-
os.close(temp_fd)
|
807 |
-
|
808 |
-
if hasattr(csv_file, 'name'):
|
809 |
-
shutil.copy2(csv_file.name, temp_csv_path)
|
810 |
-
else:
|
811 |
-
with open(temp_csv_path, 'wb') as temp_file:
|
812 |
-
if hasattr(csv_file, 'seek'):
|
813 |
-
csv_file.seek(0)
|
814 |
-
if hasattr(csv_file, 'read'):
|
815 |
-
shutil.copyfileobj(csv_file, temp_file)
|
816 |
-
else:
|
817 |
-
temp_file.write(csv_file)
|
818 |
-
|
819 |
-
if not os.path.exists(temp_csv_path):
|
820 |
-
raise FileNotFoundError(f"Failed to create temporary CSV file at {temp_csv_path}")
|
821 |
|
822 |
# Compute metrics
|
823 |
results = compute_metrics(
|
824 |
-
csv_path=
|
825 |
dataset=dataset.lower(),
|
826 |
split=split,
|
827 |
num_workers=4
|
828 |
)
|
829 |
|
830 |
if isinstance(results, str):
|
831 |
-
|
832 |
-
return f"Evaluation error: {results}"
|
833 |
|
834 |
# Process results
|
835 |
processed_results = {
|
@@ -838,6 +825,23 @@ def process_submission(
|
|
838 |
"recall@20": round(results['recall@20'] * 100, 2),
|
839 |
"mrr": round(results['mrr'] * 100, 2)
|
840 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
841 |
|
842 |
# Save files to HuggingFace Hub
|
843 |
try:
|
@@ -845,30 +849,17 @@ def process_submission(
|
|
845 |
csv_filename = f"predictions_{timestamp}.csv"
|
846 |
csv_path_in_repo = f"submissions/{folder_name}/{csv_filename}"
|
847 |
hub_storage.save_to_hub(
|
848 |
-
file_content=
|
849 |
path_in_repo=csv_path_in_repo,
|
850 |
commit_message=f"Add submission: {method_name} by {team_name}"
|
851 |
)
|
|
|
852 |
|
853 |
# 2. Save metadata
|
854 |
-
submission_data = {
|
855 |
-
**meta_data,
|
856 |
-
"results": processed_results,
|
857 |
-
"status": "pending_review", # or "approved"
|
858 |
-
"submission_date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
859 |
-
"csv_path": csv_path_in_repo
|
860 |
-
}
|
861 |
-
|
862 |
-
metadata_fd, temp_metadata_path = tempfile.mkstemp(suffix='.json')
|
863 |
-
temp_files.append(temp_metadata_path)
|
864 |
-
os.close(metadata_fd)
|
865 |
-
|
866 |
-
with open(temp_metadata_path, 'w') as f:
|
867 |
-
json.dump(submission_data, f, indent=4)
|
868 |
-
|
869 |
metadata_path = f"submissions/{folder_name}/metadata_{timestamp}.json"
|
|
|
870 |
hub_storage.save_to_hub(
|
871 |
-
file_content=
|
872 |
path_in_repo=metadata_path,
|
873 |
commit_message=f"Add metadata: {method_name} by {team_name}"
|
874 |
)
|
@@ -881,16 +872,10 @@ def process_submission(
|
|
881 |
"team_name": team_name
|
882 |
}
|
883 |
|
884 |
-
latest_fd, temp_latest_path = tempfile.mkstemp(suffix='.json')
|
885 |
-
temp_files.append(temp_latest_path)
|
886 |
-
os.close(latest_fd)
|
887 |
-
|
888 |
-
with open(temp_latest_path, 'w') as f:
|
889 |
-
json.dump(latest_info, f, indent=4)
|
890 |
-
|
891 |
latest_path = f"submissions/{folder_name}/latest.json"
|
|
|
892 |
hub_storage.save_to_hub(
|
893 |
-
file_content=
|
894 |
path_in_repo=latest_path,
|
895 |
commit_message=f"Update latest submission info for {method_name}"
|
896 |
)
|
@@ -900,7 +885,7 @@ def process_submission(
|
|
900 |
|
901 |
# Send confirmation email and update leaderboard data
|
902 |
# send_submission_confirmation(meta_data, processed_results)
|
903 |
-
update_leaderboard_data(
|
904 |
|
905 |
forum.add_submission_post(method_name, dataset, split)
|
906 |
forum_display = forum.format_posts_for_display()
|
|
|
122 |
|
123 |
# Initialize storage once at startup
|
124 |
try:
|
125 |
+
REPO_ID = "snap-stanford/stark-leaderboard" # Replace with your space name
|
126 |
hub_storage = HubStorage(REPO_ID)
|
127 |
forum = SubmissionForum(hub_storage=hub_storage)
|
128 |
except Exception as e:
|
|
|
797 |
folder_name = f"{sanitize_name(method_name)}_{sanitize_name(team_name)}"
|
798 |
|
799 |
# Process CSV file
|
800 |
+
csv_content = None
|
801 |
if isinstance(csv_file, str):
|
802 |
+
with open(csv_file, 'r') as f:
|
803 |
+
csv_content = f.read()
|
804 |
+
elif hasattr(csv_file, 'name'):
|
805 |
+
with open(csv_file.name, 'r') as f:
|
806 |
+
csv_content = f.read()
|
807 |
else:
|
808 |
+
return "Error: Invalid CSV file", forum.format_posts_for_display()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
809 |
|
810 |
# Compute metrics
|
811 |
results = compute_metrics(
|
812 |
+
csv_path=csv_file if isinstance(csv_file, str) else csv_file.name,
|
813 |
dataset=dataset.lower(),
|
814 |
split=split,
|
815 |
num_workers=4
|
816 |
)
|
817 |
|
818 |
if isinstance(results, str):
|
819 |
+
return f"Evaluation error: {results}", forum.format_posts_for_display()
|
|
|
820 |
|
821 |
# Process results
|
822 |
processed_results = {
|
|
|
825 |
"recall@20": round(results['recall@20'] * 100, 2),
|
826 |
"mrr": round(results['mrr'] * 100, 2)
|
827 |
}
|
828 |
+
|
829 |
+
meta_data = {
|
830 |
+
"Method Name": method_name,
|
831 |
+
"Team Name": team_name,
|
832 |
+
"Dataset": dataset,
|
833 |
+
"Split": split,
|
834 |
+
"Contact Email(s)": contact_email,
|
835 |
+
"Code Repository": code_repo,
|
836 |
+
"Model Description": model_description,
|
837 |
+
"Hardware": hardware,
|
838 |
+
"(Optional) Paper link": paper_link,
|
839 |
+
"Model Type": model_type,
|
840 |
+
"results": processed_results,
|
841 |
+
"status": "pending_review",
|
842 |
+
"submission_date": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
843 |
+
}
|
844 |
+
|
845 |
|
846 |
# Save files to HuggingFace Hub
|
847 |
try:
|
|
|
849 |
csv_filename = f"predictions_{timestamp}.csv"
|
850 |
csv_path_in_repo = f"submissions/{folder_name}/{csv_filename}"
|
851 |
hub_storage.save_to_hub(
|
852 |
+
file_content=csv_content,
|
853 |
path_in_repo=csv_path_in_repo,
|
854 |
commit_message=f"Add submission: {method_name} by {team_name}"
|
855 |
)
|
856 |
+
meta_data["csv_path"] = csv_path_in_repo
|
857 |
|
858 |
# 2. Save metadata
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
859 |
metadata_path = f"submissions/{folder_name}/metadata_{timestamp}.json"
|
860 |
+
metadata_content = json.dumps(meta_data, indent=4)
|
861 |
hub_storage.save_to_hub(
|
862 |
+
file_content=metadata_content, # Pass JSON string directly
|
863 |
path_in_repo=metadata_path,
|
864 |
commit_message=f"Add metadata: {method_name} by {team_name}"
|
865 |
)
|
|
|
872 |
"team_name": team_name
|
873 |
}
|
874 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
875 |
latest_path = f"submissions/{folder_name}/latest.json"
|
876 |
+
latest_content = json.dumps(latest_info, indent=4)
|
877 |
hub_storage.save_to_hub(
|
878 |
+
file_content=latest_content, # Pass JSON string directly
|
879 |
path_in_repo=latest_path,
|
880 |
commit_message=f"Update latest submission info for {method_name}"
|
881 |
)
|
|
|
885 |
|
886 |
# Send confirmation email and update leaderboard data
|
887 |
# send_submission_confirmation(meta_data, processed_results)
|
888 |
+
update_leaderboard_data(meta_data)
|
889 |
|
890 |
forum.add_submission_post(method_name, dataset, split)
|
891 |
forum_display = forum.format_posts_for_display()
|
submissions/debug_test_a/latest.json
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
/tmp/tmplbsqy_x8.json
|
|
|
|
submissions/debug_test_a/metadata_20241121_005531.json
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
/tmp/tmpcd1864kh.json
|
|
|
|
submissions/debug_test_a/predictions_20241121_005531.csv
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
/tmp/gradio/c6ce39e8ff7b6df1194eaa8460676f88c8351a09a43683ea4d8b76acc4544cfc/submissions_debug_submission_none_predictions_20241024_125801.csv
|
|
|
|
submissions/forum_posts.json
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
[
|
2 |
-
{
|
3 |
-
"message": "\ud83d\udce5 New submission: debug_test on human_generated_eval/mag",
|
4 |
-
"timestamp": "2024-11-21 00:55:49",
|
5 |
-
"post_type": "submission"
|
6 |
-
}
|
7 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|