Spaces:
Runtime error
Runtime error
Commit
Β·
507ee5d
1
Parent(s):
159f589
redirect to logout if token is expired
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import pandas as pd
|
|
| 3 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 4 |
from gradio.themes import Base, colors, sizes
|
| 5 |
from gradio_leaderboard import Leaderboard, SelectColumns
|
|
|
|
| 6 |
|
| 7 |
from src.about import CITATION_BUTTON_LABEL, CITATION_BUTTON_TEXT, EVALUATION_QUEUE_TEXT, INTRODUCTION_TEXT, TITLE
|
| 8 |
from src.datamodel.data import F1Data
|
|
@@ -156,13 +157,21 @@ def add_solution_cbk(
|
|
| 156 |
)
|
| 157 |
|
| 158 |
|
| 159 |
-
def gate_submission(
|
| 160 |
"""
|
| 161 |
@brief Toggles the visibility of the login box and submission panel based on the user's login status.
|
| 162 |
"""
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
|
| 168 |
def get_theme():
|
|
@@ -189,6 +198,8 @@ def get_theme():
|
|
| 189 |
blocks = gr.Blocks(css=custom_css, theme=get_theme())
|
| 190 |
with blocks:
|
| 191 |
|
|
|
|
|
|
|
| 192 |
gr.Image(
|
| 193 |
"assets/banner.png",
|
| 194 |
interactive=False,
|
|
@@ -289,7 +300,7 @@ with blocks:
|
|
| 289 |
blocks.load(lambda: leaderboard_df, inputs=[], outputs=[leaderboard_component])
|
| 290 |
|
| 291 |
# On initial load (and after OAuth redirect), toggle the UI based on login status.
|
| 292 |
-
blocks.load(gate_submission, inputs=None, outputs=[login_box, submit_panel])
|
| 293 |
|
| 294 |
|
| 295 |
logger.info("Scheduler")
|
|
|
|
| 3 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 4 |
from gradio.themes import Base, colors, sizes
|
| 5 |
from gradio_leaderboard import Leaderboard, SelectColumns
|
| 6 |
+
from huggingface_hub import whoami
|
| 7 |
|
| 8 |
from src.about import CITATION_BUTTON_LABEL, CITATION_BUTTON_TEXT, EVALUATION_QUEUE_TEXT, INTRODUCTION_TEXT, TITLE
|
| 9 |
from src.datamodel.data import F1Data
|
|
|
|
| 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.
|
| 163 |
"""
|
| 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), ""
|
| 168 |
+
try:
|
| 169 |
+
whoami(token.token)
|
| 170 |
+
logger.info("TOKEN IS VALID")
|
| 171 |
+
return gr.update(visible=False), gr.update(visible=True), ""
|
| 172 |
+
except Exception:
|
| 173 |
+
logger.info("TOKEN HAS EXPIRED")
|
| 174 |
+
return gr.update(visible=True), gr.update(visible=False), '<script>window.location.href = "/logout";</script>'
|
| 175 |
|
| 176 |
|
| 177 |
def get_theme():
|
|
|
|
| 198 |
blocks = gr.Blocks(css=custom_css, theme=get_theme())
|
| 199 |
with blocks:
|
| 200 |
|
| 201 |
+
reload_html = gr.HTML(visible=False)
|
| 202 |
+
|
| 203 |
gr.Image(
|
| 204 |
"assets/banner.png",
|
| 205 |
interactive=False,
|
|
|
|
| 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")
|