mshuaibi commited on
Commit
aa9b736
·
1 Parent(s): 7672017

support private submissions

Browse files
Files changed (1) hide show
  1. app.py +47 -28
app.py CHANGED
@@ -288,6 +288,7 @@ def add_new_eval(
288
  mail: str,
289
  training_set: str,
290
  additional_info: str,
 
291
  profile: gr.OAuthProfile,
292
  ) -> str:
293
  """Add a new evaluation to the leaderboard."""
@@ -296,7 +297,7 @@ def add_new_eval(
296
  # Validate email address
297
  _, parsed_mail = parseaddr(mail)
298
  if "@" not in parsed_mail:
299
- yield "⚠️ Please provide a valid email address."
300
  return
301
 
302
  # Check monthly submission limit (5 submissions per month)
@@ -313,20 +314,20 @@ def add_new_eval(
313
  ]
314
 
315
  if len(current_month_submissions) >= 5:
316
- yield f"⚠️ You have reached the monthly submission limit of 5 submissions. Please try again next month."
317
  return
318
 
319
  # Validate file submission
320
  if path_to_file is None:
321
- yield "⚠️ Please upload a file."
322
  return
323
 
324
  if not (path_to_file.endswith(".npz") or path_to_file.endswith(".json")):
325
- yield "⚠️ Please submit a valid npz or json file"
326
  return
327
 
328
  # Evaluate the submission
329
- yield "⚙️ Evaluating your submission...(do not close/refresh this page!)"
330
  metrics = evaluate(
331
  leaderboard_data.target_paths[eval_type],
332
  path_to_file,
@@ -335,18 +336,7 @@ def add_new_eval(
335
 
336
  submission_time = datetime.today().strftime("%Y-%m-%d-%H:%M")
337
 
338
- # Upload submission file
339
- yield "☁️ Uploading submission file..."
340
- api.upload_file(
341
- repo_id=SUBMISSION_DATASET,
342
- path_or_fileobj=path_to_file,
343
- path_in_repo=f"{organization}/{model}/submissions/{training_set}/{contact_key}_{submission_time}_{os.path.basename(path_to_file)}",
344
- repo_type="dataset",
345
- token=TOKEN,
346
- )
347
-
348
  # Update leaderboard data
349
- yield "📋 Updating leaderboard data..."
350
  eval_results, _ = leaderboard_data.load_eval_data()
351
  eval_entry = {
352
  "Model": model,
@@ -367,20 +357,40 @@ def add_new_eval(
367
  else:
368
  eval_results[eval_type] = eval_results[eval_type].add_item(eval_entry)
369
 
370
- data_file_name = leaderboard_data.result_paths[eval_type]
371
-
372
- # Upload results
373
- yield "💾 Saving results to database..."
374
- with tempfile.NamedTemporaryFile(suffix=".parquet") as tmp_file:
375
- eval_results[eval_type].to_parquet(tmp_file.name)
376
  api.upload_file(
377
- repo_id=RESULTS_DATASET,
378
- path_or_fileobj=tmp_file.name,
379
- path_in_repo=f"data/{data_file_name}",
380
  repo_type="dataset",
381
  token=TOKEN,
382
  )
383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  # Save contact information
385
  contact_info = {
386
  "model": model,
@@ -401,8 +411,9 @@ def add_new_eval(
401
 
402
  leaderboard_data.contact_infos.push_to_hub(CONTACT_DATASET, token=TOKEN)
403
 
404
- success_str = f"✅ Model {model} is successfully evaluated and stored in our database.\nPlease wait an hour and refresh the leaderboard to see your results displayed."
405
- yield success_str
 
406
  except Exception as e:
407
  print(f"Error during submission: {e}")
408
  yield (
@@ -599,11 +610,16 @@ def create_submission_interface() -> Tuple[gr.components.Component, ...]:
599
  label="Eval Type",
600
  interactive=True,
601
  )
 
 
 
602
  with gr.Column():
603
  gr.LoginButton()
604
  with gr.Column():
605
  submit_button = gr.Button("Submit Eval")
606
- submission_result = gr.Textbox(label="Status")
 
 
607
 
608
  return (
609
  submit_button,
@@ -618,6 +634,7 @@ def create_submission_interface() -> Tuple[gr.components.Component, ...]:
618
  dataset,
619
  additional_info,
620
  submission_result,
 
621
  )
622
 
623
 
@@ -669,6 +686,7 @@ def create_interface() -> gr.Blocks:
669
  dataset,
670
  additional_info,
671
  submission_result,
 
672
  ) = create_submission_interface()
673
 
674
  submit_button.click(
@@ -684,6 +702,7 @@ def create_interface() -> gr.Blocks:
684
  mail,
685
  dataset,
686
  additional_info,
 
687
  ],
688
  submission_result,
689
  )
 
288
  mail: str,
289
  training_set: str,
290
  additional_info: str,
291
+ submission_visibility: str,
292
  profile: gr.OAuthProfile,
293
  ) -> str:
294
  """Add a new evaluation to the leaderboard."""
 
297
  # Validate email address
298
  _, parsed_mail = parseaddr(mail)
299
  if "@" not in parsed_mail:
300
+ yield "⚠️ Please provide a valid email address."
301
  return
302
 
303
  # Check monthly submission limit (5 submissions per month)
 
314
  ]
315
 
316
  if len(current_month_submissions) >= 5:
317
+ yield f"⚠️ You have reached the monthly submission limit of 5 submissions. Please try again next month."
318
  return
319
 
320
  # Validate file submission
321
  if path_to_file is None:
322
+ yield "⚠️ Please upload a file."
323
  return
324
 
325
  if not (path_to_file.endswith(".npz") or path_to_file.endswith(".json")):
326
+ yield "⚠️ Please submit a valid npz or json file"
327
  return
328
 
329
  # Evaluate the submission
330
+ yield "⚙️ Evaluating your submission...(do not close/refresh this page!)"
331
  metrics = evaluate(
332
  leaderboard_data.target_paths[eval_type],
333
  path_to_file,
 
336
 
337
  submission_time = datetime.today().strftime("%Y-%m-%d-%H:%M")
338
 
 
 
 
 
 
 
 
 
 
 
339
  # Update leaderboard data
 
340
  eval_results, _ = leaderboard_data.load_eval_data()
341
  eval_entry = {
342
  "Model": model,
 
357
  else:
358
  eval_results[eval_type] = eval_results[eval_type].add_item(eval_entry)
359
 
360
+ if submission_visibility == "Public":
361
+ # Upload submission file
362
+ yield "☁️ Uploading submission file..."
 
 
 
363
  api.upload_file(
364
+ repo_id=SUBMISSION_DATASET,
365
+ path_or_fileobj=path_to_file,
366
+ path_in_repo=f"{organization}/{model}/submissions/{training_set}/{contact_key}_{submission_time}_{os.path.basename(path_to_file)}",
367
  repo_type="dataset",
368
  token=TOKEN,
369
  )
370
 
371
+ data_file_name = leaderboard_data.result_paths[eval_type]
372
+
373
+ # Upload results
374
+ yield "💾 Saving results to database..."
375
+ with tempfile.NamedTemporaryFile(suffix=".parquet") as tmp_file:
376
+ eval_results[eval_type].to_parquet(tmp_file.name)
377
+ api.upload_file(
378
+ repo_id=RESULTS_DATASET,
379
+ path_or_fileobj=tmp_file.name,
380
+ path_in_repo=f"data/{data_file_name}",
381
+ repo_type="dataset",
382
+ token=TOKEN,
383
+ )
384
+ else:
385
+ eval_df = Dataset.from_dict({k: [v] for k, v in eval_entry.items()})
386
+ private_df = leaderboard_data._get_eval_df_from_results(
387
+ {eval_type: eval_df}, eval_type
388
+ )
389
+ private_df["Model"] = model
390
+ private_df.columns = [col.replace("\n", " ") for col in private_df.columns]
391
+ private_df.set_index("Model")
392
+ yield f"✅ Private evaluation complete. Please consider submitting publicly once you are comfortable with the results.\n{private_df}"
393
+
394
  # Save contact information
395
  contact_info = {
396
  "model": model,
 
411
 
412
  leaderboard_data.contact_infos.push_to_hub(CONTACT_DATASET, token=TOKEN)
413
 
414
+ if submission_visibility == "Public":
415
+ success_str = f"✅ Model {model} is successfully evaluated and stored in our database.\nPlease wait an hour and refresh the leaderboard to see your results displayed."
416
+ yield success_str
417
  except Exception as e:
418
  print(f"Error during submission: {e}")
419
  yield (
 
610
  label="Eval Type",
611
  interactive=True,
612
  )
613
+ submission_visibility = gr.Dropdown(
614
+ label="Submission visibility", choices=["Public", "Private"]
615
+ )
616
  with gr.Column():
617
  gr.LoginButton()
618
  with gr.Column():
619
  submit_button = gr.Button("Submit Eval")
620
+ submission_result = gr.Textbox(
621
+ label="Status", autoscroll=False, lines=10
622
+ )
623
 
624
  return (
625
  submit_button,
 
634
  dataset,
635
  additional_info,
636
  submission_result,
637
+ submission_visibility,
638
  )
639
 
640
 
 
686
  dataset,
687
  additional_info,
688
  submission_result,
689
+ submission_visibility,
690
  ) = create_submission_interface()
691
 
692
  submit_button.click(
 
702
  mail,
703
  dataset,
704
  additional_info,
705
+ submission_visibility,
706
  ],
707
  submission_result,
708
  )