Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
7722634
1
Parent(s):
7ded1c5
toggle ui based on login
Browse files- app.py +16 -0
- src/submission/submit.py +20 -33
app.py
CHANGED
@@ -147,6 +147,18 @@ def add_solution_cbk(
|
|
147 |
)
|
148 |
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
blocks = gr.Blocks(css=custom_css)
|
151 |
with blocks:
|
152 |
gr.Image(
|
@@ -206,6 +218,7 @@ with blocks:
|
|
206 |
submit_panel = gr.Group(visible=False)
|
207 |
with submit_panel:
|
208 |
with gr.Row():
|
|
|
209 |
with gr.Column():
|
210 |
system_name_textbox = gr.Textbox(label=AutoEvalColumn.system.name)
|
211 |
org_textbox = gr.Textbox(label=AutoEvalColumn.organization.name)
|
@@ -246,6 +259,9 @@ with blocks:
|
|
246 |
# The work already happened in the background - refresh_leaderboard_data().
|
247 |
blocks.load(lambda: leaderboard_df, inputs=[], outputs=[leaderboard_component])
|
248 |
|
|
|
|
|
|
|
249 |
|
250 |
logger.info("Scheduler")
|
251 |
scheduler = BackgroundScheduler()
|
|
|
147 |
)
|
148 |
|
149 |
|
150 |
+
def gate_submission(profile: gr.OAuthProfile | None):
|
151 |
+
"""
|
152 |
+
Returns:
|
153 |
+
- login_box visibility (True if logged OUT)
|
154 |
+
- submit_panel visibility (True if logged IN)
|
155 |
+
- status line
|
156 |
+
"""
|
157 |
+
if profile is None:
|
158 |
+
return gr.update(visible=True), gr.update(visible=False), "You're not signed in."
|
159 |
+
return gr.update(visible=False), gr.update(visible=True), f"Signed in as @{profile.username}"
|
160 |
+
|
161 |
+
|
162 |
blocks = gr.Blocks(css=custom_css)
|
163 |
with blocks:
|
164 |
gr.Image(
|
|
|
218 |
submit_panel = gr.Group(visible=False)
|
219 |
with submit_panel:
|
220 |
with gr.Row():
|
221 |
+
status_line = gr.Markdown() # "Signed in as @user"
|
222 |
with gr.Column():
|
223 |
system_name_textbox = gr.Textbox(label=AutoEvalColumn.system.name)
|
224 |
org_textbox = gr.Textbox(label=AutoEvalColumn.organization.name)
|
|
|
259 |
# The work already happened in the background - refresh_leaderboard_data().
|
260 |
blocks.load(lambda: leaderboard_df, inputs=[], outputs=[leaderboard_component])
|
261 |
|
262 |
+
# On initial load (and after OAuth redirect), toggle the UI based on login status.
|
263 |
+
blocks.load(gate_submission, inputs=None, outputs=[login_box, submit_panel, status_line])
|
264 |
+
|
265 |
|
266 |
logger.info("Scheduler")
|
267 |
scheduler = BackgroundScheduler()
|
src/submission/submit.py
CHANGED
@@ -79,6 +79,26 @@ def add_new_solutions(
|
|
79 |
)
|
80 |
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
def _validate_all_submissions_present(
|
83 |
lbdb: F1Data,
|
84 |
pd_ds: pd.DataFrame,
|
@@ -102,36 +122,3 @@ def _validate_all_submissions_present(
|
|
102 |
raise ValueError(f"Mismatched problem IDs: {len(missing)} missing, {len(unknown)} unknown")
|
103 |
if len(pd_ds) > len(lbdb.code_problem_ids):
|
104 |
return ValueError("Duplicate problem IDs exist in uploaded file")
|
105 |
-
|
106 |
-
|
107 |
-
def fetch_sub_claim(oauth_token: gr.OAuthToken | None) -> dict | None:
|
108 |
-
if oauth_token is None:
|
109 |
-
return None
|
110 |
-
provider = os.getenv("OPENID_PROVIDER_URL")
|
111 |
-
if not provider:
|
112 |
-
return None
|
113 |
-
try:
|
114 |
-
oidc_meta = requests.get(f"{provider}/.well-known/openid-configuration", timeout=5).json()
|
115 |
-
userinfo_ep = oidc_meta["userinfo_endpoint"]
|
116 |
-
claims = requests.get(userinfo_ep, headers={"Authorization": f"Bearer {oauth_token.token}"}, timeout=5).json()
|
117 |
-
# Typical fields: sub (stable id), preferred_username, name, picture
|
118 |
-
return {
|
119 |
-
"sub": claims.get("sub"),
|
120 |
-
"preferred_username": claims.get("preferred_username"),
|
121 |
-
"name": claims.get("name"),
|
122 |
-
}
|
123 |
-
except Exception:
|
124 |
-
return None
|
125 |
-
|
126 |
-
|
127 |
-
# --- on-load gate: show/hide submit panel based on login state ---
|
128 |
-
def gate_submission(profile: gr.OAuthProfile | None):
|
129 |
-
"""
|
130 |
-
Returns:
|
131 |
-
- login_box visibility (True if logged OUT)
|
132 |
-
- submit_panel visibility (True if logged IN)
|
133 |
-
- status line
|
134 |
-
"""
|
135 |
-
if profile is None:
|
136 |
-
return gr.update(visible=True), gr.update(visible=False), "You're not signed in."
|
137 |
-
return gr.update(visible=False), gr.update(visible=True), f"Signed in as @{profile.username}"
|
|
|
79 |
)
|
80 |
|
81 |
|
82 |
+
def fetch_sub_claim(oauth_token: gr.OAuthToken | None) -> dict | None:
|
83 |
+
if oauth_token is None:
|
84 |
+
return None
|
85 |
+
provider = os.getenv("OPENID_PROVIDER_URL")
|
86 |
+
if not provider:
|
87 |
+
return None
|
88 |
+
try:
|
89 |
+
oidc_meta = requests.get(f"{provider}/.well-known/openid-configuration", timeout=5).json()
|
90 |
+
userinfo_ep = oidc_meta["userinfo_endpoint"]
|
91 |
+
claims = requests.get(userinfo_ep, headers={"Authorization": f"Bearer {oauth_token.token}"}, timeout=5).json()
|
92 |
+
# Typical fields: sub (stable id), preferred_username, name, picture
|
93 |
+
return {
|
94 |
+
"sub": claims.get("sub"),
|
95 |
+
"preferred_username": claims.get("preferred_username"),
|
96 |
+
"name": claims.get("name"),
|
97 |
+
}
|
98 |
+
except Exception:
|
99 |
+
return None
|
100 |
+
|
101 |
+
|
102 |
def _validate_all_submissions_present(
|
103 |
lbdb: F1Data,
|
104 |
pd_ds: pd.DataFrame,
|
|
|
122 |
raise ValueError(f"Mismatched problem IDs: {len(missing)} missing, {len(unknown)} unknown")
|
123 |
if len(pd_ds) > len(lbdb.code_problem_ids):
|
124 |
return ValueError("Duplicate problem IDs exist in uploaded file")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|