NidhiS09 commited on
Commit
4af020b
Β·
verified Β·
1 Parent(s): 7ee2ab0

Temp page.py for vqa

Browse files
Files changed (1) hide show
  1. challenges/vqa/page.py +149 -0
challenges/vqa/page.py CHANGED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from datetime import datetime, timezone
3
+
4
+ import gradio as gr
5
+ import pandas as pd
6
+
7
+ from auth_utils import get_user_greeting, get_daily_cap_info
8
+ from hf_utils import (
9
+ _load_leaderboard_df,
10
+ _load_user_submissions,
11
+ _create_submission_record,
12
+ _count_submissions_today,
13
+ _get_cap_for_phase,
14
+ _today_utc_str,
15
+ )
16
+ from config import DAILY_SUBMISSION_CAP, SUBMISSIONS_TOKEN
17
+ from challenges.vqa.config import (
18
+ PHASES, LEADERBOARD_METRICS, DEFAULT_SORT_METRIC,
19
+ LEADERBOARD_FILE, CHALLENGE_PHASE,
20
+ )
21
+ # VQA reuses the OL submit handler (challenge_type passed as argument)
22
+ from challenges.object_localization.page import handle_submit, load_my_submissions
23
+
24
+
25
+ def build_vqa_page(demo: gr.Blocks) -> None:
26
+ with demo.route("Visual Question Answering", "/vqa") as vqa_page:
27
+
28
+ with gr.Row():
29
+ with gr.Column(scale=5):
30
+ gr.Markdown("# πŸ€” Visual Question Answering Challenge")
31
+ gr.Markdown(
32
+ "Answer open-ended questions about images taken by blind users. "
33
+ "Models are evaluated on answer accuracy and relevance."
34
+ )
35
+ with gr.Column(scale=1, min_width=160):
36
+ gr.LoginButton(size="lg")
37
+ vqa_greeting = gr.Markdown("πŸ‘‹ Log in to submit.")
38
+
39
+ gr.Markdown("---")
40
+
41
+ with gr.Tabs():
42
+
43
+ # ── Leaderboard ──
44
+ with gr.TabItem("πŸ† Leaderboard"):
45
+ gr.Markdown("### VQA Challenge Rankings")
46
+ gr.Markdown("Ranked by **Accuracy** (descending).")
47
+ vqa_lb_msg = gr.Markdown("")
48
+ vqa_lb_table = gr.Dataframe(interactive=False, wrap=True)
49
+ vqa_refresh_lb_btn = gr.Button("πŸ”„ Refresh Leaderboard", variant="secondary", size="sm")
50
+
51
+ def refresh_vqa_leaderboard(profile: gr.OAuthProfile | None):
52
+ cols = ["Rank", "Team", "Model", "Accuracy", "Scored At"]
53
+ empty_df = pd.DataFrame(columns=cols)
54
+ try:
55
+ df = _load_leaderboard_df(LEADERBOARD_FILE, LEADERBOARD_METRICS)
56
+ if not df.empty and "phase_codename" in df.columns:
57
+ df = df[df["phase_codename"] == CHALLENGE_PHASE]
58
+ except Exception as e:
59
+ return empty_df, f"❌ Could not load leaderboard: {e}", get_user_greeting(profile)
60
+ if df.empty:
61
+ return empty_df, "ℹ️ No VQA submissions yet. Be the first!", get_user_greeting(profile)
62
+ df_display = df.copy()
63
+ df_display.insert(0, "Rank", range(1, len(df_display) + 1))
64
+ if "timestamp" in df_display.columns:
65
+ df_display["Scored At"] = pd.to_datetime(
66
+ df_display["timestamp"], unit="s", errors="coerce"
67
+ ).dt.strftime("%d %b %Y, %I:%M %p")
68
+ display_cols = ["Rank", "team", "model", "overall", "Scored At"]
69
+ df_display = df_display[[c for c in display_cols if c in df_display.columns]]
70
+ df_display.rename(columns={"team": "Team", "model": "Model", "overall": "Accuracy"}, inplace=True)
71
+ return df_display, "", get_user_greeting(profile)
72
+
73
+ vqa_refresh_lb_btn.click(refresh_vqa_leaderboard, outputs=[vqa_lb_table, vqa_lb_msg, vqa_greeting])
74
+ vqa_page.load(refresh_vqa_leaderboard, outputs=[vqa_lb_table, vqa_lb_msg, vqa_greeting])
75
+
76
+ # ── Submit ──
77
+ with gr.TabItem("πŸš€ Submit Predictions"):
78
+ with gr.Row():
79
+ vqa_submit_greeting = gr.Markdown("πŸ‘‹ Log in with HuggingFace to submit.")
80
+ vqa_cap_info = gr.Markdown("")
81
+ gr.Markdown("---")
82
+ with gr.Row():
83
+ with gr.Column(scale=3):
84
+ gr.Markdown("#### Upload VQA Results")
85
+ vqa_file_input = gr.File(label="Choose a JSON file", file_types=[".json"])
86
+ with gr.Column(scale=2):
87
+ gr.Markdown("#### Submission Info")
88
+ vqa_team_input = gr.Textbox(label="Team / Display Name")
89
+ vqa_model_input = gr.Textbox(label="Model Name")
90
+ vqa_phase_input = gr.Dropdown(
91
+ label="Phase",
92
+ choices=[p["label"] for p in PHASES],
93
+ value=PHASES[0]["label"],
94
+ )
95
+ vqa_submit_btn = gr.Button("Submit (Queue for Evaluation)", variant="primary", size="lg")
96
+ vqa_submit_status = gr.Markdown("")
97
+ vqa_sid_box = gr.Code(label="Submission ID", visible=False)
98
+
99
+ def do_vqa_submit(file, team, model, phase, profile: gr.OAuthProfile | None):
100
+ msg, sid = handle_submit(file, team, model, phase, "Visual Question Answering", profile)
101
+ return msg, gr.update(value=sid, visible=bool(sid))
102
+
103
+ vqa_submit_btn.click(
104
+ do_vqa_submit,
105
+ inputs=[vqa_file_input, vqa_team_input, vqa_model_input, vqa_phase_input],
106
+ outputs=[vqa_submit_status, vqa_sid_box],
107
+ )
108
+
109
+ def update_vqa_submit_ui(profile: gr.OAuthProfile | None):
110
+ return get_user_greeting(profile), get_daily_cap_info(profile, PHASES)
111
+
112
+ vqa_page.load(update_vqa_submit_ui, outputs=[vqa_submit_greeting, vqa_cap_info])
113
+
114
+ # ── My Submissions ──
115
+ with gr.TabItem("πŸ“‹ My Submissions"):
116
+ vqa_my_sub_greeting = gr.Markdown("πŸ‘‹ Log in to view your submissions.")
117
+ vqa_my_sub_stats = gr.Markdown("")
118
+ with gr.Row():
119
+ vqa_phase_filter = gr.Dropdown(
120
+ label="Filter by Phase",
121
+ choices=["All"] + [p["codename"] for p in PHASES],
122
+ value="All",
123
+ scale=2,
124
+ )
125
+ vqa_refresh_my_btn = gr.Button("πŸ”„ Refresh", variant="secondary", scale=1)
126
+ vqa_my_sub_msg = gr.Markdown("")
127
+ vqa_my_sub_table = gr.Dataframe(interactive=False, wrap=True)
128
+
129
+ def refresh_vqa_my_subs(phase_filter, profile: gr.OAuthProfile | None):
130
+ df, msg, stats = load_my_submissions(phase_filter, profile)
131
+ if not df.empty and "Challenge Type" in df.columns:
132
+ df = df[df["Challenge Type"] == "Visual Question Answering"]
133
+ return df, msg, stats, get_user_greeting(profile)
134
+
135
+ vqa_refresh_my_btn.click(
136
+ refresh_vqa_my_subs,
137
+ inputs=[vqa_phase_filter],
138
+ outputs=[vqa_my_sub_table, vqa_my_sub_msg, vqa_my_sub_stats, vqa_my_sub_greeting],
139
+ )
140
+ vqa_phase_filter.change(
141
+ refresh_vqa_my_subs,
142
+ inputs=[vqa_phase_filter],
143
+ outputs=[vqa_my_sub_table, vqa_my_sub_msg, vqa_my_sub_stats, vqa_my_sub_greeting],
144
+ )
145
+ vqa_page.load(
146
+ refresh_vqa_my_subs,
147
+ inputs=[vqa_phase_filter],
148
+ outputs=[vqa_my_sub_table, vqa_my_sub_msg, vqa_my_sub_stats, vqa_my_sub_greeting],
149
+ )