HFswapnil commited on
Commit
086fe55
Β·
verified Β·
1 Parent(s): 68b4bf2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +97 -24
main.py CHANGED
@@ -664,37 +664,42 @@ with demo.route("Object Localization", "/object-localization") as obj_loc:
664
  )
665
 
666
  # ── VQA PAGE ──────────────────────────────────────────────────────────
667
- with demo.route("Visual Question Answering", "/vqa"):
668
  # gr.Markdown("# πŸ€” Visual Question Answering")
669
  # gr.Markdown("### πŸ”’ Coming Soon")
670
  # gr.Markdown(
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.")
683
 
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
 
@@ -702,33 +707,101 @@ with demo.route("Visual Question Answering", "/vqa") as vqa_page:
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")
 
664
  )
665
 
666
  # ── VQA PAGE ──────────────────────────────────────────────────────────
667
+ # with demo.route("Visual Question Answering", "/vqa"):
668
  # gr.Markdown("# πŸ€” Visual Question Answering")
669
  # gr.Markdown("### πŸ”’ Coming Soon")
670
  # gr.Markdown(
671
  # "This challenge is currently under development. "
672
  # )
673
 
674
+ # ── VQA PAGE ──────────────────────────────────────────────────────────
675
  with demo.route("Visual Question Answering", "/vqa") as vqa_page:
676
+
677
  with gr.Row():
678
  with gr.Column(scale=5):
679
  gr.Markdown("# πŸ€” Visual Question Answering Challenge")
680
+ gr.Markdown(
681
+ "Answer open-ended questions about images taken by blind users. "
682
+ "Models are evaluated on answer accuracy and relevance."
683
+ )
684
  with gr.Column(scale=1, min_width=160):
685
  gr.LoginButton(size="lg")
686
+ vqa_greeting = gr.Markdown("πŸ‘‹ Log in to submit.")
687
 
688
  gr.Markdown("---")
689
 
690
  with gr.Tabs():
691
+
692
+ # 1. Leaderboard Tab
693
  with gr.TabItem("πŸ† Leaderboard"):
694
  gr.Markdown("### VQA Challenge Rankings")
695
+ gr.Markdown("Ranked by **Accuracy** (descending).")
696
 
697
+ vqa_lb_msg = gr.Markdown("")
698
  vqa_lb_table = gr.Dataframe(interactive=False, wrap=True)
699
  refresh_vqa_lb_btn = gr.Button("πŸ”„ Refresh Leaderboard", variant="secondary", size="sm")
700
 
701
  def refresh_vqa_leaderboard(profile: gr.OAuthProfile | None):
702
+ # Task 2: Default empty DF structure
703
  cols = ["Rank", "Team", "Model", "Accuracy", "Scored At"]
704
  empty_df = pd.DataFrame(columns=cols)
705
 
 
707
  df = _load_leaderboard_df()
708
  # Filter for VQA challenge specifically
709
  if not df.empty and "challenge_type" in df.columns:
710
+ df = df[df["challenge_type"].str.lower() == "visual question answering"]
711
  except Exception as e:
712
+ return empty_df, f"❌ Could not load leaderboard: {e}", get_user_greeting(profile)
713
 
714
  if df.empty:
 
715
  return empty_df, "ℹ️ No VQA submissions yet. Be the first!", get_user_greeting(profile)
716
 
 
717
  df_display = df.copy()
718
  df_display.insert(0, "Rank", range(1, len(df_display) + 1))
719
+
720
+ if "timestamp" in df_display.columns:
721
+ df_display["Scored At"] = pd.to_datetime(
722
+ df_display["timestamp"], unit="s", errors="coerce"
723
+ ).dt.strftime("%d %b %Y, %I:%M %p")
724
+
725
+ # Filter to VQA specific metrics
726
+ display_cols = ["Rank", "team", "model", "accuracy", "Scored At"]
727
+ df_display = df_display[[c for c in display_cols if c in df_display.columns]]
728
+ df_display.rename(columns={"team": "Team", "model": "Model", "accuracy": "Accuracy"}, inplace=True)
729
+
730
  return df_display, "", get_user_greeting(profile)
731
 
732
+ refresh_vqa_lb_btn.click(refresh_vqa_leaderboard, outputs=[vqa_lb_table, vqa_lb_msg, vqa_greeting])
733
+ vqa_page.load(refresh_vqa_leaderboard, outputs=[vqa_lb_table, vqa_lb_msg, vqa_greeting])
734
+
735
+ # 2. Submit Tab
736
+ with gr.TabItem("πŸš€ Submit Predictions"):
737
+ with gr.Row():
738
+ vqa_submit_greeting = gr.Markdown("πŸ‘‹ Log in with HuggingFace to submit.")
739
+ vqa_cap_info = gr.Markdown("")
740
+ gr.Markdown("---")
741
+ with gr.Row():
742
+ with gr.Column(scale=3):
743
+ gr.Markdown("#### Upload VQA Results")
744
+ vqa_file_input = gr.File(label="Choose a JSON file", file_types=[".json"])
745
+ with gr.Column(scale=2):
746
+ gr.Markdown("#### Submission Info")
747
+ vqa_team_input = gr.Textbox(label="Team / Display Name")
748
+ vqa_model_input = gr.Textbox(label="Model Name")
749
+ vqa_phase_input = gr.Dropdown(
750
+ label="Phase",
751
+ choices=[p["label"] for p in PHASES],
752
+ value=PHASES[0]["label"],
753
+ )
754
+ vqa_submit_btn = gr.Button("Submit (Queue for Evaluation)", variant="primary", size="lg")
755
+ vqa_submit_status = gr.Markdown("")
756
+ vqa_sid_box = gr.Code(label="Submission ID", visible=False)
757
+
758
+ def do_vqa_submit(file, team, model, phase, profile: gr.OAuthProfile | None):
759
+ # We pass "Visual Question Answering" as the challenge type
760
+ msg, sid = handle_submit(file, team, model, phase, "Visual Question Answering", profile)
761
+ return msg, gr.update(value=sid, visible=bool(sid))
762
+
763
+ vqa_submit_btn.click(
764
+ do_vqa_submit,
765
+ inputs=[vqa_file_input, vqa_team_input, vqa_model_input, vqa_phase_input],
766
+ outputs=[vqa_submit_status, vqa_sid_box],
767
  )
768
+
769
+ def update_vqa_submit_ui(profile: gr.OAuthProfile | None):
770
+ return get_user_greeting(profile), get_daily_cap_info(profile)
771
+
772
+ vqa_page.load(update_vqa_submit_ui, outputs=[vqa_submit_greeting, vqa_cap_info])
773
+
774
+ # 3. My Submissions Tab
775
+ with gr.TabItem("πŸ“‹ My Submissions"):
776
+ vqa_my_sub_greeting = gr.Markdown("πŸ‘‹ Log in to view your submissions.")
777
+ vqa_my_sub_stats = gr.Markdown("")
778
+ with gr.Row():
779
+ vqa_phase_filter = gr.Dropdown(
780
+ label="Filter by Phase",
781
+ choices=["All"] + [p["codename"] for p in PHASES],
782
+ value="All",
783
+ scale=2
784
+ )
785
+ vqa_refresh_my_btn = gr.Button("πŸ”„ Refresh", variant="secondary", scale=1)
786
+ vqa_my_sub_table = gr.Dataframe(interactive=False, wrap=True)
787
+
788
+ def refresh_vqa_my_subs(phase_filter, profile: gr.OAuthProfile | None):
789
+ df, msg, stats = load_my_submissions(phase_filter, profile)
790
+ # Further filter results to only show VQA
791
+ if not df.empty and "Challenge Type" in df.columns:
792
+ df = df[df["Challenge Type"] == "Visual Question Answering"]
793
+ return df, msg, stats, get_user_greeting(profile)
794
+
795
+ vqa_refresh_my_btn.click(
796
+ refresh_vqa_my_subs,
797
+ inputs=[vqa_phase_filter],
798
+ outputs=[vqa_my_sub_table, gr.Markdown(), vqa_my_sub_stats, vqa_my_sub_greeting],
799
  )
800
+ vqa_page.load(
801
+ refresh_vqa_my_subs,
802
+ inputs=[vqa_phase_filter],
803
+ outputs=[vqa_my_sub_table, gr.Markdown(), vqa_my_sub_stats, vqa_my_sub_greeting],
804
+ )
805
  # ── ANSWER GROUNDING PAGE ─────────────────────────────────────────────
806
  with demo.route("Answer Grounding", "/answer-grounding"):
807
  gr.Markdown("# πŸ“ Answer Grounding")