tomerz-aai commited on
Commit
fddc90b
·
1 Parent(s): e22e375
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -157,6 +157,17 @@ def add_solution_cbk(
157
  )
158
 
159
 
 
 
 
 
 
 
 
 
 
 
 
160
  def gate_submission(token: gr.OAuthToken | None):
161
  """
162
  @brief Toggles the visibility of the login box and submission panel based on the user's login status.
@@ -164,14 +175,14 @@ def gate_submission(token: gr.OAuthToken | None):
164
  logger.info("TOKEN %s", token)
165
  if token is None:
166
  logger.info("NO TOKEN")
167
- return gr.update(visible=True), gr.update(visible=False), gr.update(value="")
168
  try:
169
  whoami(token.token)
170
  logger.info("TOKEN IS VALID")
171
- return gr.update(visible=False), gr.update(visible=True), gr.update(value="")
172
  except Exception:
173
  logger.info("TOKEN HAS EXPIRED")
174
- return gr.update(visible=True), gr.update(visible=False), gr.update(value='<script>window.location.href = "/logout";</script>')
175
 
176
 
177
  def get_theme():
@@ -295,12 +306,15 @@ with blocks:
295
  elem_id="citation-block",
296
  )
297
 
 
 
 
298
  # UI refresh triggers latest data swap.
299
  # The work already happened in the background - refresh_leaderboard_data().
300
  blocks.load(lambda: leaderboard_df, inputs=[], outputs=[leaderboard_component])
301
 
302
  # On initial load (and after OAuth redirect), toggle the UI based on login status.
303
- blocks.load(gate_submission, inputs=None, outputs=[login_box, submit_panel, reload_html])
304
 
305
 
306
  logger.info("Scheduler")
 
157
  )
158
 
159
 
160
+ def check_valid_token(token: gr.OAuthToken | None):
161
+ logger.info("TOKEN %s", token)
162
+ if token is None:
163
+ return ""
164
+ try:
165
+ whoami(token.token)
166
+ return ""
167
+ except Exception:
168
+ return '<script>window.location.href = "/logout";</script>'
169
+
170
+
171
  def gate_submission(token: gr.OAuthToken | None):
172
  """
173
  @brief Toggles the visibility of the login box and submission panel based on the user's login status.
 
175
  logger.info("TOKEN %s", token)
176
  if token is None:
177
  logger.info("NO TOKEN")
178
+ return gr.update(visible=True), gr.update(visible=False)
179
  try:
180
  whoami(token.token)
181
  logger.info("TOKEN IS VALID")
182
+ return gr.update(visible=False), gr.update(visible=True)
183
  except Exception:
184
  logger.info("TOKEN HAS EXPIRED")
185
+ return gr.update(visible=True), gr.update(visible=False)
186
 
187
 
188
  def get_theme():
 
306
  elem_id="citation-block",
307
  )
308
 
309
+ # Trigger reload if token is expired
310
+ blocks.load(check_valid_token, outputs=reload_html)
311
+
312
  # UI refresh triggers latest data swap.
313
  # The work already happened in the background - refresh_leaderboard_data().
314
  blocks.load(lambda: leaderboard_df, inputs=[], outputs=[leaderboard_component])
315
 
316
  # On initial load (and after OAuth redirect), toggle the UI based on login status.
317
+ blocks.load(gate_submission, inputs=None, outputs=[login_box, submit_panel])
318
 
319
 
320
  logger.info("Scheduler")