Shiyu Zhao commited on
Commit
c2c76a6
·
1 Parent(s): 36648a1

Update space

Browse files
Files changed (1) hide show
  1. app.py +97 -0
app.py CHANGED
@@ -212,6 +212,93 @@ def sanitize_name(name):
212
  """Sanitize name for file system use"""
213
  return re.sub(r'[^a-zA-Z0-9]', '_', name)
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  def save_submission(submission_data, csv_file):
216
  """
217
  Save submission data and CSV file using model_name_team_name format
@@ -780,6 +867,9 @@ with gr.Blocks(css=css) as demo:
780
  submit_btn = gr.Button("Submit", variant="primary")
781
  result = gr.Textbox(label="Submission Status", interactive=False)
782
 
 
 
 
783
  # Set up event handlers
784
  model_type_filter.change(
785
  update_tables,
@@ -787,6 +877,13 @@ with gr.Blocks(css=css) as demo:
787
  outputs=all_dfs
788
  )
789
 
 
 
 
 
 
 
 
790
  submit_btn.click(
791
  process_submission,
792
  inputs=[
 
212
  """Sanitize name for file system use"""
213
  return re.sub(r'[^a-zA-Z0-9]', '_', name)
214
 
215
+ def scan_submissions_directory():
216
+ """
217
+ Scans the submissions directory and updates the leaderboard tables with all submitted results.
218
+ Returns a dictionary mapping split names to lists of submissions.
219
+ """
220
+ global df_synthesized_full, df_synthesized_10, df_human_generated
221
+
222
+ try:
223
+ # Get submissions directory content from HuggingFace hub
224
+ submissions_content = hub_storage.list_repo_content("submissions")
225
+ if not submissions_content:
226
+ print("No submissions directory found or empty")
227
+ return
228
+
229
+ # Track submissions for each split
230
+ submissions_by_split = {
231
+ 'test': [],
232
+ 'test-0.1': [],
233
+ 'human_generated_eval': []
234
+ }
235
+
236
+ # Iterate through team folders
237
+ for folder in submissions_content:
238
+ if not folder.endswith('/'): # Skip files
239
+ continue
240
+
241
+ try:
242
+ # Get latest.json to find most recent submission
243
+ latest_content = hub_storage.get_repo_content(f"{folder}latest.json")
244
+ if not latest_content:
245
+ continue
246
+
247
+ latest_info = json.loads(latest_content)
248
+ if latest_info.get('status') != 'pending_review': # Only include approved submissions
249
+ timestamp = latest_info.get('latest_submission')
250
+ if not timestamp:
251
+ continue
252
+
253
+ # Get metadata file for this submission
254
+ metadata_path = f"{folder}metadata_{timestamp}.json"
255
+ metadata_content = hub_storage.get_repo_content(metadata_path)
256
+ if not metadata_content:
257
+ continue
258
+
259
+ submission_data = json.loads(metadata_content)
260
+ split = submission_data.get('Split')
261
+ if split in submissions_by_split:
262
+ submissions_by_split[split].append(submission_data)
263
+
264
+ # Update corresponding DataFrame
265
+ update_leaderboard_data(submission_data)
266
+
267
+ except Exception as e:
268
+ print(f"Error processing folder {folder}: {str(e)}")
269
+ continue
270
+
271
+ print("Leaderboard initialized with existing submissions:")
272
+ for split, submissions in submissions_by_split.items():
273
+ print(f"{split}: {len(submissions)} submissions")
274
+
275
+ return submissions_by_split
276
+
277
+ except Exception as e:
278
+ print(f"Error scanning submissions directory: {str(e)}")
279
+ return None
280
+
281
+ def initialize_leaderboard():
282
+ """
283
+ Initialize the leaderboard with baseline results and submitted results.
284
+ """
285
+ global df_synthesized_full, df_synthesized_10, df_human_generated
286
+
287
+ try:
288
+ # First, initialize with baseline results
289
+ df_synthesized_full = pd.DataFrame(data_synthesized_full)
290
+ df_synthesized_10 = pd.DataFrame(data_synthesized_10)
291
+ df_human_generated = pd.DataFrame(data_human_generated)
292
+
293
+ # Then scan and add submitted results
294
+ scan_submissions_directory()
295
+
296
+ print("Leaderboard initialization complete")
297
+
298
+ except Exception as e:
299
+ print(f"Error initializing leaderboard: {str(e)}")
300
+
301
+
302
  def save_submission(submission_data, csv_file):
303
  """
304
  Save submission data and CSV file using model_name_team_name format
 
867
  submit_btn = gr.Button("Submit", variant="primary")
868
  result = gr.Textbox(label="Submission Status", interactive=False)
869
 
870
+ # Initialize leaderboard at startup
871
+ initialize_leaderboard()
872
+
873
  # Set up event handlers
874
  model_type_filter.change(
875
  update_tables,
 
877
  outputs=all_dfs
878
  )
879
 
880
+ # Initial table update
881
+ demo.load(
882
+ update_tables,
883
+ inputs=[model_type_filter],
884
+ outputs=all_dfs
885
+ )
886
+
887
  submit_btn.click(
888
  process_submission,
889
  inputs=[