HFswapnil commited on
Commit
68b4bf2
Β·
verified Β·
1 Parent(s): 1712e94

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +27 -30
main.py CHANGED
@@ -671,13 +671,12 @@ with demo.route("Visual Question Answering", "/vqa"):
671
  # "This challenge is currently under development. "
672
  # )
673
 
 
 
674
  with gr.Row():
675
  with gr.Column(scale=5):
676
  gr.Markdown("# πŸ€” Visual Question Answering Challenge")
677
- gr.Markdown(
678
- "Answer open-ended questions about images taken by blind users. "
679
- "Models are evaluated on answer accuracy and relevance."
680
- )
681
  with gr.Column(scale=1, min_width=160):
682
  gr.LoginButton(size="lg")
683
  vqa_greeting = gr.Markdown("πŸ‘‹ Log in to view or submit.")
@@ -685,53 +684,51 @@ with demo.route("Visual Question Answering", "/vqa"):
685
  gr.Markdown("---")
686
 
687
  with gr.Tabs():
688
- # Task 2: Leaderboard Tab showing Empty DF if no submissions
689
  with gr.TabItem("πŸ† Leaderboard"):
690
  gr.Markdown("### VQA Challenge Rankings")
691
  lb_msg = gr.Markdown("")
692
 
693
- # The Dataframe component that will hold our submissions (or empty columns)
694
  vqa_lb_table = gr.Dataframe(interactive=False, wrap=True)
695
  refresh_vqa_lb_btn = gr.Button("πŸ”„ Refresh Leaderboard", variant="secondary", size="sm")
696
 
697
  def refresh_vqa_leaderboard(profile: gr.OAuthProfile | None):
698
- # 1. Define the empty DataFrame structure for VQA
699
- empty_df = pd.DataFrame(columns=["Rank", "Team", "Model", "Accuracy", "Scored At"])
 
700
 
701
  try:
702
  df = _load_leaderboard_df()
703
- # Filter for VQA submissions if they exist
704
  if not df.empty and "challenge_type" in df.columns:
705
- df = df[df["challenge_type"] == "vqa"]
706
  except Exception as e:
707
- return empty_df, f"❌ Could not load leaderboard: {e}", get_user_greeting(profile)
708
 
709
- # 2. Return the empty DataFrame if no VQA submissions exist
710
  if df.empty:
711
- return empty_df, "ℹ️ No VQA submissions yet. Be the first to conquer the challenge!", get_user_greeting(profile)
 
712
 
713
- # 3. Process existing submissions (if any)
714
  df_display = df.copy()
715
  df_display.insert(0, "Rank", range(1, len(df_display) + 1))
716
- if "timestamp" in df_display.columns:
717
- df_display["Scored At"] = pd.to_datetime(
718
- df_display["timestamp"], unit="s", errors="coerce"
719
- ).dt.strftime("%d %b %Y, %I:%M %p")
720
-
721
- # Keep only relevant columns and rename them cleanly
722
- cols_to_keep = ["Rank", "team", "model", "accuracy", "Scored At"]
723
- df_display = df_display[[c for c in cols_to_keep if c in df_display.columns]]
724
- df_display.rename(columns={"team": "Team", "model": "Model", "accuracy": "Accuracy"}, inplace=True)
725
-
726
  return df_display, "", get_user_greeting(profile)
727
 
728
- # Bind the functions to the load and button click events
729
- refresh_vqa_lb_btn.click(refresh_vqa_leaderboard, outputs=[vqa_lb_table, lb_msg, vqa_greeting])
730
- vqa_page.load(refresh_vqa_leaderboard, outputs=[vqa_lb_table, lb_msg, vqa_greeting])
 
 
 
 
 
 
 
 
 
731
 
732
- # (Optional) You can add the "πŸš€ Submit Predictions" tab here later using the
733
- # same pattern as the Object Localization page!
734
-
735
  # ── ANSWER GROUNDING PAGE ─────────────────────────────────────────────
736
  with demo.route("Answer Grounding", "/answer-grounding"):
737
  gr.Markdown("# πŸ“ Answer Grounding")
 
671
  # "This challenge is currently under development. "
672
  # )
673
 
674
+ # ── VQA PAGE ──────────────────────────────────────────────────────────
675
+ with demo.route("Visual Question Answering", "/vqa") as vqa_page:
676
  with gr.Row():
677
  with gr.Column(scale=5):
678
  gr.Markdown("# πŸ€” Visual Question Answering Challenge")
679
+ gr.Markdown("Answer open-ended questions about images taken by blind users.")
 
 
 
680
  with gr.Column(scale=1, min_width=160):
681
  gr.LoginButton(size="lg")
682
  vqa_greeting = gr.Markdown("πŸ‘‹ Log in to view or submit.")
 
684
  gr.Markdown("---")
685
 
686
  with gr.Tabs():
687
+ # Task 2: Leaderboard Tab
688
  with gr.TabItem("πŸ† Leaderboard"):
689
  gr.Markdown("### VQA Challenge Rankings")
690
  lb_msg = gr.Markdown("")
691
 
692
+ # This ensures an empty DF is shown if there are no submissions
693
  vqa_lb_table = gr.Dataframe(interactive=False, wrap=True)
694
  refresh_vqa_lb_btn = gr.Button("πŸ”„ Refresh Leaderboard", variant="secondary", size="sm")
695
 
696
  def refresh_vqa_leaderboard(profile: gr.OAuthProfile | None):
697
+ # Define structure for the empty state
698
+ cols = ["Rank", "Team", "Model", "Accuracy", "Scored At"]
699
+ empty_df = pd.DataFrame(columns=cols)
700
 
701
  try:
702
  df = _load_leaderboard_df()
703
+ # Filter for VQA challenge specifically
704
  if not df.empty and "challenge_type" in df.columns:
705
+ df = df[df["challenge_type"].str.lower() == "vqa"]
706
  except Exception as e:
707
+ return empty_df, f"❌ Error: {e}", get_user_greeting(profile)
708
 
 
709
  if df.empty:
710
+ # Task 2: Return empty DF if no submissions
711
+ return empty_df, "ℹ️ No VQA submissions yet. Be the first!", get_user_greeting(profile)
712
 
713
+ # Process the data if it exists
714
  df_display = df.copy()
715
  df_display.insert(0, "Rank", range(1, len(df_display) + 1))
716
+ # ... (rest of your processing logic)
 
 
 
 
 
 
 
 
 
717
  return df_display, "", get_user_greeting(profile)
718
 
719
+ # --- CRITICAL: These must be indented INSIDE 'with demo.route' ---
720
+ refresh_vqa_lb_btn.click(
721
+ refresh_vqa_leaderboard,
722
+ outputs=[vqa_lb_table, lb_msg, vqa_greeting]
723
+ )
724
+
725
+ # This was the line causing your error!
726
+ # It's now properly indented under 'vqa_page'
727
+ vqa_page.load(
728
+ refresh_vqa_leaderboard,
729
+ outputs=[vqa_lb_table, lb_msg, vqa_greeting]
730
+ )
731
 
 
 
 
732
  # ── ANSWER GROUNDING PAGE ─────────────────────────────────────────────
733
  with demo.route("Answer Grounding", "/answer-grounding"):
734
  gr.Markdown("# πŸ“ Answer Grounding")