yangzhitao commited on
Commit
8125e59
·
1 Parent(s): b30e7f7

refactor: standardize user ID display format and enhance benchmark result handling in create_submit_tab function

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -369,7 +369,7 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
369
 
370
  # ========== Login Section (First Step) ==========
371
  login_button = gr.LoginButton()
372
- current_user_display = gr.Markdown(value="**Submitter ID:** Loading...")
373
 
374
  with gr.Row():
375
  gr.Markdown(SUBMISSION_INSTRUCTIONS_TEXT, elem_classes="markdown-text")
@@ -379,11 +379,11 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
379
  """Get current HuggingFace user ID from the visiting user (not the server token)"""
380
  if oauth_profile is None:
381
  # User is not logged in
382
- return "**Submitter ID:** Not logged in"
383
  # User is logged in, get user ID from OAuth profile
384
  # OAuth profile contains 'sub' (user ID) and 'preferred_username' fields
385
  user_id = oauth_profile.get("preferred_username") or oauth_profile.get("sub", "Unknown")
386
- return f"**Submitter ID:** {user_id}"
387
 
388
  # Container for all form sections - will be hidden if user is not logged in
389
  form_container = gr.Column(visible=False)
@@ -537,7 +537,7 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
537
  revision: str,
538
  precision: str,
539
  benchmark_checkbox_values: list[bool],
540
- benchmark_result_values: list[float],
541
  ) -> str:
542
  """Build JSON from form inputs"""
543
  if not model_name or not model_name.strip():
@@ -567,6 +567,7 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
567
  strict=True,
568
  ):
569
  if checkbox_checked:
 
570
  results[benchmark.key] = {"acc": float(result_value) if result_value is not None else None}
571
 
572
  if not results:
@@ -588,16 +589,15 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
588
  model_type: str,
589
  json_str: str,
590
  commit_message: str,
 
591
  *benchmark_values: list[bool | float],
592
- oauth_profile: gr.OAuthProfile | None = None,
593
  ):
594
  """Submit with either form data or JSON"""
595
  # Check if user is logged in
596
- if oauth_profile is None:
 
597
  return styled_error("Please log in before submitting.")
598
-
599
- # Extract user_id from OAuth profile
600
- user_id = oauth_profile.get("preferred_username") or oauth_profile.get("sub", None)
601
  if not user_id:
602
  return styled_error("Unable to get user ID. Please try logging in again.")
603
 
@@ -626,14 +626,20 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
626
 
627
  # Split into checkbox values and result values
628
  benchmark_checkbox_values: list[bool] = []
629
- benchmark_result_values: list[float] = []
630
- for checkbox_value, result_value in benchmark_values:
631
- benchmark_checkbox_values.append(checkbox_value)
632
- benchmark_result_values.append(result_value) # pyright: ignore[reportArgumentType]
 
 
633
 
634
  try:
635
  final_json = build_json_from_form(
636
- model, revision, precision, benchmark_checkbox_values, benchmark_result_values
 
 
 
 
637
  )
638
  except ValueError as e:
639
  return styled_error(str(e))
@@ -699,6 +705,7 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
699
  model_type,
700
  json_str,
701
  commit_textbox,
 
702
  *benchmark_values,
703
  ],
704
  outputs=submission_result,
 
369
 
370
  # ========== Login Section (First Step) ==========
371
  login_button = gr.LoginButton()
372
+ current_user_display = gr.Markdown(value="Submitter ID: Loading...")
373
 
374
  with gr.Row():
375
  gr.Markdown(SUBMISSION_INSTRUCTIONS_TEXT, elem_classes="markdown-text")
 
379
  """Get current HuggingFace user ID from the visiting user (not the server token)"""
380
  if oauth_profile is None:
381
  # User is not logged in
382
+ return "Submitter ID: Not logged in"
383
  # User is logged in, get user ID from OAuth profile
384
  # OAuth profile contains 'sub' (user ID) and 'preferred_username' fields
385
  user_id = oauth_profile.get("preferred_username") or oauth_profile.get("sub", "Unknown")
386
+ return f"Submitter ID: **{user_id}**"
387
 
388
  # Container for all form sections - will be hidden if user is not logged in
389
  form_container = gr.Column(visible=False)
 
537
  revision: str,
538
  precision: str,
539
  benchmark_checkbox_values: list[bool],
540
+ benchmark_result_values: list[float | None],
541
  ) -> str:
542
  """Build JSON from form inputs"""
543
  if not model_name or not model_name.strip():
 
567
  strict=True,
568
  ):
569
  if checkbox_checked:
570
+ # TODO: metric
571
  results[benchmark.key] = {"acc": float(result_value) if result_value is not None else None}
572
 
573
  if not results:
 
589
  model_type: str,
590
  json_str: str,
591
  commit_message: str,
592
+ current_user_display: str,
593
  *benchmark_values: list[bool | float],
 
594
  ):
595
  """Submit with either form data or JSON"""
596
  # Check if user is logged in
597
+ user_id_match = re.match(r"\*\*(.+)\*\*", current_user_display)
598
+ if not user_id_match:
599
  return styled_error("Please log in before submitting.")
600
+ user_id = user_id_match.group(1)
 
 
601
  if not user_id:
602
  return styled_error("Unable to get user ID. Please try logging in again.")
603
 
 
626
 
627
  # Split into checkbox values and result values
628
  benchmark_checkbox_values: list[bool] = []
629
+ benchmark_result_values: list[float | None] = []
630
+ for i, value in enumerate(benchmark_values):
631
+ if i % 2 == 0:
632
+ benchmark_checkbox_values.append(bool(value))
633
+ else:
634
+ benchmark_result_values.append(float(value) if value is not None else None) # pyright: ignore[reportArgumentType]
635
 
636
  try:
637
  final_json = build_json_from_form(
638
+ model,
639
+ revision,
640
+ precision,
641
+ benchmark_checkbox_values,
642
+ benchmark_result_values,
643
  )
644
  except ValueError as e:
645
  return styled_error(str(e))
 
705
  model_type,
706
  json_str,
707
  commit_textbox,
708
+ current_user_display,
709
  *benchmark_values,
710
  ],
711
  outputs=submission_result,