yangzhitao commited on
Commit
f163070
·
1 Parent(s): ace97cb

refactor: streamline user ID extraction and enhance error handling in create_submit_tab function for improved user experience

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -597,11 +597,13 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
597
  if not current_user_display:
598
  return styled_error("Please log in before submitting.")
599
  user_id_match = re.match(r"\*\*(.+)\*\*", current_user_display)
600
- if user_id_match:
601
- user_id = user_id_match.group(1)
602
- if not user_id:
603
- msg = f"Unable to get user ID ({current_user_display!r}). Please try logging in again."
604
- return styled_error(msg)
 
 
605
 
606
  # If JSON is provided, use it; otherwise build from form
607
  if json_str and json_str.strip():
@@ -615,7 +617,7 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
615
  # Build JSON from form
616
  # benchmark_values contains pairs of (checkbox_value, result_value) for each benchmark
617
  benchmarks_list = get_benchmarks()
618
- if len(benchmark_values) != len(benchmarks_list):
619
  print(
620
  dedent(f"""
621
  Invalid benchmark form data. Please check your inputs.
 
597
  if not current_user_display:
598
  return styled_error("Please log in before submitting.")
599
  user_id_match = re.match(r"\*\*(.+)\*\*", current_user_display)
600
+ if not user_id_match:
601
+ msg = f"Unable to get user ID ({current_user_display!r}). Please try logging in again."
602
+ return styled_error(msg)
603
+ user_id = user_id_match.group(1)
604
+ if not user_id:
605
+ msg = f"Unable to get user ID ({current_user_display!r}). Please try logging in again."
606
+ return styled_error(msg)
607
 
608
  # If JSON is provided, use it; otherwise build from form
609
  if json_str and json_str.strip():
 
617
  # Build JSON from form
618
  # benchmark_values contains pairs of (checkbox_value, result_value) for each benchmark
619
  benchmarks_list = get_benchmarks()
620
+ if len(benchmark_values) != len(benchmarks_list) * 2:
621
  print(
622
  dedent(f"""
623
  Invalid benchmark form data. Please check your inputs.