Shiyu Zhao commited on
Commit
46c7e88
·
1 Parent(s): 6f5b93e

Update space

Browse files
app.py CHANGED
@@ -40,24 +40,26 @@ class ForumPost:
40
  self.post_type = post_type # 'submission' or 'status_update'
41
 
42
  class SubmissionForum:
43
- def __init__(self, forum_file="forum_posts.json"):
44
  self.forum_file = forum_file
 
45
  self.posts = self._load_posts()
46
 
47
  def _load_posts(self):
48
- """Load existing posts from JSON file"""
49
  try:
50
- with open(self.forum_file, 'r') as f:
51
- posts_data = json.load(f)
 
 
52
  return [ForumPost(**post) for post in posts_data]
53
- except FileNotFoundError:
54
  return []
55
  except Exception as e:
56
  print(f"Error loading forum posts: {e}")
57
  return []
58
 
59
  def _save_posts(self):
60
- """Save posts to JSON file"""
61
  try:
62
  posts_data = [
63
  {
@@ -67,8 +69,16 @@ class SubmissionForum:
67
  }
68
  for post in self.posts
69
  ]
70
- with open(self.forum_file, 'w') as f:
71
- json.dump(posts_data, f, indent=4)
 
 
 
 
 
 
 
 
72
  except Exception as e:
73
  print(f"Error saving forum posts: {e}")
74
 
@@ -114,10 +124,11 @@ class SubmissionForum:
114
  try:
115
  REPO_ID = "snap-stanford/stark-leaderboard" # Replace with your space name
116
  hub_storage = HubStorage(REPO_ID)
 
117
  except Exception as e:
118
- raise RuntimeError(f"Failed to initialize HuggingFace Hub storage: {e}")
 
119
 
120
- forum = SubmissionForum()
121
 
122
  def process_single_instance(args):
123
  """Process a single instance with improved validation and error handling"""
@@ -892,6 +903,7 @@ def process_submission(
892
  update_leaderboard_data(submission_data)
893
 
894
  forum.add_submission_post(method_name, dataset, split)
 
895
 
896
  # Return success message
897
  return f"""
@@ -910,12 +922,12 @@ def process_submission(
910
  https://huggingface.co/spaces/{REPO_ID}/tree/main/submissions/{folder_name}
911
 
912
  Please refresh the page to see your submission in the leaderboard.
913
- """
914
 
915
  except Exception as e:
916
  error_message = f"Error processing submission: {str(e)}"
917
  # send_error_notification(meta_data, error_message)
918
- return error_message
919
  finally:
920
  # Clean up temporary files
921
  for temp_file in temp_files:
@@ -1159,13 +1171,13 @@ with gr.Blocks(css=css) as demo:
1159
  method_name, team_name, dataset, split, contact_email,
1160
  code_repo, csv_file, model_description, hardware, paper_link, model_type, honor_code
1161
  ],
1162
- outputs=result
1163
- ).success( # Add a success handler to update tables after successful submission
1164
- fn=update_tables,
1165
- inputs=[model_type_filter],
1166
- outputs=all_dfs
1167
  )
1168
-
1169
  # Initial table update
1170
  demo.load(
1171
  update_tables,
 
40
  self.post_type = post_type # 'submission' or 'status_update'
41
 
42
  class SubmissionForum:
43
+ def __init__(self, forum_file="forum_posts.json", hub_storage=None):
44
  self.forum_file = forum_file
45
+ self.hub_storage = hub_storage
46
  self.posts = self._load_posts()
47
 
48
  def _load_posts(self):
49
+ """Load existing posts from JSON file in the hub"""
50
  try:
51
+ # Try to get content from hub
52
+ content = self.hub_storage.get_file_content(self.forum_file)
53
+ if content:
54
+ posts_data = json.loads(content)
55
  return [ForumPost(**post) for post in posts_data]
 
56
  return []
57
  except Exception as e:
58
  print(f"Error loading forum posts: {e}")
59
  return []
60
 
61
  def _save_posts(self):
62
+ """Save posts to JSON file in the hub"""
63
  try:
64
  posts_data = [
65
  {
 
69
  }
70
  for post in self.posts
71
  ]
72
+
73
+ # Convert to JSON string
74
+ json_content = json.dumps(posts_data, indent=4)
75
+
76
+ # Save to hub
77
+ self.hub_storage.save_to_hub(
78
+ file_content=json_content,
79
+ path_in_repo=self.forum_file,
80
+ commit_message="Update forum posts"
81
+ )
82
  except Exception as e:
83
  print(f"Error saving forum posts: {e}")
84
 
 
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:
129
+ print(f"Failed to initialize forum with hub storage: {e}")
130
+ forum = SubmissionForum(hub_storage=hub_storage)
131
 
 
132
 
133
  def process_single_instance(args):
134
  """Process a single instance with improved validation and error handling"""
 
903
  update_leaderboard_data(submission_data)
904
 
905
  forum.add_submission_post(method_name, dataset, split)
906
+ forum_display = forum.format_posts_for_display()
907
 
908
  # Return success message
909
  return f"""
 
922
  https://huggingface.co/spaces/{REPO_ID}/tree/main/submissions/{folder_name}
923
 
924
  Please refresh the page to see your submission in the leaderboard.
925
+ """, forum_display
926
 
927
  except Exception as e:
928
  error_message = f"Error processing submission: {str(e)}"
929
  # send_error_notification(meta_data, error_message)
930
+ return error_message, forum.format_posts_for_display()
931
  finally:
932
  # Clean up temporary files
933
  for temp_file in temp_files:
 
1171
  method_name, team_name, dataset, split, contact_email,
1172
  code_repo, csv_file, model_description, hardware, paper_link, model_type, honor_code
1173
  ],
1174
+ outputs=[result, forum_display]
1175
+ ).then( # Chain the forum refresh after submission
1176
+ fn=lambda: forum.format_posts_for_display(),
1177
+ inputs=[],
1178
+ outputs=[forum_display]
1179
  )
1180
+
1181
  # Initial table update
1182
  demo.load(
1183
  update_tables,
submissions/debug_test_abc/latest.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "latest_submission": "20241120_231229",
3
- "status": "pending_review",
4
- "method_name": "debug_test",
5
- "team_name": "abc"
6
- }
 
 
 
 
 
 
 
submissions/debug_test_abc/metadata_20241120_231229.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "Method Name": "debug_test",
3
- "Team Name": "abc",
4
- "Dataset": "mag",
5
- "Split": "human_generated_eval",
6
- "Contact Email(s)": "a@stanford.edu",
7
- "Code Repository": "https://github.com/snap-stanford/stark",
8
- "Model Description": "abc",
9
- "Hardware": "a100",
10
- "(Optional) Paper link": "",
11
- "Model Type": "Others",
12
- "results": {
13
- "hit@1": 28.57,
14
- "hit@5": 41.67,
15
- "recall@20": 35.95,
16
- "mrr": 35.94
17
- },
18
- "status": "pending_review",
19
- "submission_date": "2024-11-20 23:12:48",
20
- "csv_path": "submissions/debug_test_abc/predictions_20241120_231229.csv"
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
submissions/debug_test_abc/predictions_20241120_231229.csv DELETED
The diff for this file is too large to render. See raw diff
 
submissions/debugging_test_abc/latest.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "latest_submission": "20241115_013853",
3
- "status": "pending_review",
4
- "method_name": "debugging_test",
5
- "team_name": "abc"
6
- }
 
 
 
 
 
 
 
submissions/debugging_test_abc/metadata_20241115_013853.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "Method Name": "debugging_test",
3
- "Team Name": "abc",
4
- "Dataset": "mag",
5
- "Split": "human_generated_eval",
6
- "Contact Email(s)": "a@stanford.edu",
7
- "Code Repository": "https://github.com/",
8
- "Model Description": "abc",
9
- "Hardware": "a100",
10
- "(Optional) Paper link": "",
11
- "Model Type": "Others",
12
- "results": {
13
- "hit@1": 28.57,
14
- "hit@5": 41.67,
15
- "recall@20": 35.95,
16
- "mrr": 35.94
17
- },
18
- "status": "approved",
19
- "submission_date": "2024-11-15 01:39:11",
20
- "csv_path": "submissions/debugging_test_abc/predictions_20241115_013853.csv"
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
submissions/debugging_test_abc/predictions_20241115_013853.csv DELETED
The diff for this file is too large to render. See raw diff
 
submissions/test_tester/latest.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "latest_submission": "20241115_033521",
3
- "status": "pending_review",
4
- "method_name": "test",
5
- "team_name": "tester",
6
- "reviewed_at": "2024-11-19 19:53:11"
7
- }
 
 
 
 
 
 
 
 
submissions/test_tester/metadata_20241115_033521.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "Method Name": "test",
3
- "Team Name": "tester",
4
- "Dataset": "mag",
5
- "Split": "human_generated_eval",
6
- "Contact Email(s)": "a@stanford.edu",
7
- "Code Repository": "https://github.com/",
8
- "Model Description": "a",
9
- "Hardware": "a100",
10
- "(Optional) Paper link": "",
11
- "Model Type": "Others",
12
- "results": {
13
- "hit@1": 28.57,
14
- "hit@5": 41.67,
15
- "recall@20": 35.95,
16
- "mrr": 35.94
17
- },
18
- "status": "approved",
19
- "submission_date": "2024-11-15 03:35:38",
20
- "csv_path": "submissions/test_tester/predictions_20241115_033521.csv",
21
- "reviewed_at": "2024-11-19 19:53:11"
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
submissions/test_tester/predictions_20241115_033521.csv DELETED
The diff for this file is too large to render. See raw diff