galb-dai commited on
Commit
86d80a3
·
2 Parent(s): 837b831 f0078b2

Merge branch 'main' of hf.co:spaces/double-ai/FormulaOne-Leaderboard

Browse files
Files changed (4) hide show
  1. README.md +1 -1
  2. app.py +21 -13
  3. requirements.txt +1 -1
  4. src/envs.py +2 -0
README.md CHANGED
@@ -9,7 +9,7 @@ app_file: app.py
9
  pinned: true
10
  license: apache-2.0
11
  short_description: FormulaOne Leaderboard
12
- sdk_version: 5.19.0
13
  ---
14
 
15
  # Start the configuration
 
9
  pinned: true
10
  license: apache-2.0
11
  short_description: FormulaOne Leaderboard
12
+ sdk_version: 5.42.0
13
  ---
14
 
15
  # Start the configuration
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
@@ -83,13 +84,13 @@ def add_solution_cbk(
83
  sys_type: str,
84
  submission_path: str,
85
  profile: gr.OAuthProfile | None,
86
- token: gr.OAuthToken | None,
87
  ):
88
  logger.info("Fetching user details for submission")
89
  logger.info("PROFILE %s", profile)
90
- logger.info("TOKEN %s", token)
91
 
92
- if profile is None or token is None:
93
  return styled_error("Please sign in with Hugging Face before submitting.")
94
 
95
  # Display handle and display name (may change over time)
@@ -98,20 +99,19 @@ def add_solution_cbk(
98
  logger.info(f"Display name: {display_name}")
99
 
100
  # Stable account id
101
- user_info = fetch_user_info(token)
102
  logger.info("Logged in user info: %s", user_info)
103
  stable_id = user_info.get("id") if user_info else None
104
  logger.info(f"User stable ID: {stable_id}")
105
 
106
- # TODO: find a way to invalidate login status if token is outdated
107
- # if not stable_id:
108
- # return styled_error("Could not retrieve your stable user ID. Please try signing in again.")
109
- # user_id = stable_id
110
 
111
  if not profile.username:
112
  return styled_error("Could not retrieve username. Please try signing in again.")
113
  # We rely on underscores as separators in submission ID, replace it with "-".
114
- user_id = profile.username.replace("_", "-")
115
 
116
  try:
117
  # Validating the submission file.
@@ -156,13 +156,21 @@ def add_solution_cbk(
156
  )
157
 
158
 
159
- def gate_submission(profile: gr.OAuthProfile | None):
160
  """
161
  @brief Toggles the visibility of the login box and submission panel based on the user's login status.
162
  """
163
- if profile is None:
 
 
 
 
 
 
 
 
 
164
  return gr.update(visible=True), gr.update(visible=False)
165
- return gr.update(visible=False), gr.update(visible=True)
166
 
167
 
168
  def get_theme():
@@ -240,7 +248,7 @@ with blocks:
240
  # Shown when logged OUT
241
  login_box = gr.Group(visible=True)
242
  with login_box:
243
- gr.Markdown("Please sign in to continue:")
244
  gr.LoginButton()
245
 
246
  # Shown when logged IN
 
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
 
84
  sys_type: str,
85
  submission_path: str,
86
  profile: gr.OAuthProfile | None,
87
+ oauth_token: gr.OAuthToken | None,
88
  ):
89
  logger.info("Fetching user details for submission")
90
  logger.info("PROFILE %s", profile)
91
+ logger.info("TOKEN %s", oauth_token)
92
 
93
+ if profile is None or oauth_token is None:
94
  return styled_error("Please sign in with Hugging Face before submitting.")
95
 
96
  # Display handle and display name (may change over time)
 
99
  logger.info(f"Display name: {display_name}")
100
 
101
  # Stable account id
102
+ user_info = fetch_user_info(oauth_token)
103
  logger.info("Logged in user info: %s", user_info)
104
  stable_id = user_info.get("id") if user_info else None
105
  logger.info(f"User stable ID: {stable_id}")
106
 
107
+ if not stable_id:
108
+ return styled_error("Could not retrieve your stable user ID. Please try signing in again.")
109
+ user_id = stable_id
 
110
 
111
  if not profile.username:
112
  return styled_error("Could not retrieve username. Please try signing in again.")
113
  # We rely on underscores as separators in submission ID, replace it with "-".
114
+ # user_id = profile.username.replace("_", "-")
115
 
116
  try:
117
  # Validating the submission file.
 
156
  )
157
 
158
 
159
+ def gate_submission(oauth_token: gr.OAuthToken | None):
160
  """
161
  @brief Toggles the visibility of the login box and submission panel based on the user's login status.
162
  """
163
+ logger.info("GATE TOKEN %s", oauth_token)
164
+ if oauth_token is None:
165
+ logger.info("GATE: NO TOKEN")
166
+ return gr.update(visible=True), gr.update(visible=False)
167
+ try:
168
+ whoami(oauth_token.token)
169
+ logger.info("GATE: TOKEN IS VALID")
170
+ return gr.update(visible=False), gr.update(visible=True)
171
+ except Exception:
172
+ logger.info("GATE: TOKEN HAS EXPIRED")
173
  return gr.update(visible=True), gr.update(visible=False)
 
174
 
175
 
176
  def get_theme():
 
248
  # Shown when logged OUT
249
  login_box = gr.Group(visible=True)
250
  with login_box:
251
+ gr.Markdown("Please sign in with Hugging Face to submit")
252
  gr.LoginButton()
253
 
254
  # Shown when logged IN
requirements.txt CHANGED
@@ -2,7 +2,7 @@ APScheduler
2
  black
3
  datasets
4
  pydantic==2.10.6
5
- gradio
6
  gradio[oauth]
7
  gradio_leaderboard==0.0.13
8
  gradio_client
 
2
  black
3
  datasets
4
  pydantic==2.10.6
5
+ gradio==5.42.0
6
  gradio[oauth]
7
  gradio_leaderboard==0.0.13
8
  gradio_client
src/envs.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
 
3
  from huggingface_hub import HfApi
4
 
@@ -16,6 +17,7 @@ RESULTS_REPO = f"{OWNER}/dev-f1-leaderboard-results"
16
  # If you setup a cache later, just change HF_HOME
17
  CACHE_PATH = os.getenv("HF_HOME", ".")
18
 
 
19
  print(f"{TOKEN=}")
20
  print(f"{REPO_ID=}")
21
 
 
1
  import os
2
+ import gradio as gr
3
 
4
  from huggingface_hub import HfApi
5
 
 
17
  # If you setup a cache later, just change HF_HOME
18
  CACHE_PATH = os.getenv("HF_HOME", ".")
19
 
20
+ print(f"RUNNING gradio {gr.__version__}")
21
  print(f"{TOKEN=}")
22
  print(f"{REPO_ID=}")
23