Quentin Gallouédec commited on
Commit
a3eda6f
1 Parent(s): 1a011cd

handle video not in repo and count the number of models

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -180,8 +180,12 @@ def refresh_video(df, env_id):
180
  model_id = env_df.iloc[0]["model_id"]
181
  model_sha = env_df.iloc[0]["model_sha"]
182
  repo_id = f"{user_id}/{model_id}"
183
- video_path = API.hf_hub_download(repo_id=repo_id, filename="replay.mp4", revision=model_sha, repo_type="model")
184
- return video_path
 
 
 
 
185
  else:
186
  return None
187
 
@@ -211,6 +215,9 @@ This leaderboard is quite empty... 😢
211
  Be the first to submit your model!
212
  Check the tab "🚀 Getting my agent evaluated"
213
  """
 
 
 
214
 
215
 
216
  css = """
@@ -228,25 +235,27 @@ h3 {
228
 
229
 
230
  def update_globals():
231
- global dataframes, winner_texts, video_pathes, df
232
  df = get_leaderboard_df()
233
  all_env_ids = [env_id for env_ids in ALL_ENV_IDS.values() for env_id in env_ids]
234
  dataframes = {env_id: format_df(select_env(df, env_id)) for env_id in all_env_ids}
235
  winner_texts = {env_id: refresh_winner(df, env_id) for env_id in all_env_ids}
236
  video_pathes = {env_id: refresh_video(df, env_id) for env_id in all_env_ids}
 
237
 
238
 
239
  update_globals()
240
 
241
 
242
  def refresh():
243
- global dataframes, winner_texts, video_pathes
244
- return list(dataframes.values()) + list(winner_texts.values()) + [list(video_pathes.values())[0]]
245
 
246
 
247
  with gr.Blocks(css=css) as demo:
248
  with open("texts/heading.md") as fp:
249
  gr.Markdown(fp.read())
 
250
  with gr.Tabs(elem_classes="tab-buttons") as tabs:
251
  with gr.TabItem("🏅 Leaderboard"):
252
  all_gr_dfs = {}
@@ -295,7 +304,7 @@ with gr.Blocks(css=css) as demo:
295
  with open("texts/about.md") as fp:
296
  gr.Markdown(fp.read())
297
 
298
- demo.load(refresh, outputs=list(all_gr_dfs.values()) + list(all_gr_winners.values()))
299
 
300
  scheduler = BackgroundScheduler()
301
  scheduler.add_job(func=backend_routine, trigger="interval", seconds=REFRESH_RATE, max_instances=1)
 
180
  model_id = env_df.iloc[0]["model_id"]
181
  model_sha = env_df.iloc[0]["model_sha"]
182
  repo_id = f"{user_id}/{model_id}"
183
+ try:
184
+ video_path = API.hf_hub_download(repo_id=repo_id, filename="replay.mp4", revision=model_sha, repo_type="model")
185
+ return video_path
186
+ except Exception as e:
187
+ logger.error(f"Error while downloading video for {env_id}: {e}")
188
+ return None
189
  else:
190
  return None
191
 
 
215
  Be the first to submit your model!
216
  Check the tab "🚀 Getting my agent evaluated"
217
  """
218
+
219
+ def refresh_num_models(df):
220
+ return f"The leaderboard currently contains {len(df):,} models."
221
 
222
 
223
  css = """
 
235
 
236
 
237
  def update_globals():
238
+ global dataframes, winner_texts, video_pathes, num_models_str, df
239
  df = get_leaderboard_df()
240
  all_env_ids = [env_id for env_ids in ALL_ENV_IDS.values() for env_id in env_ids]
241
  dataframes = {env_id: format_df(select_env(df, env_id)) for env_id in all_env_ids}
242
  winner_texts = {env_id: refresh_winner(df, env_id) for env_id in all_env_ids}
243
  video_pathes = {env_id: refresh_video(df, env_id) for env_id in all_env_ids}
244
+ num_models_str = refresh_num_models(df)
245
 
246
 
247
  update_globals()
248
 
249
 
250
  def refresh():
251
+ global dataframes, winner_texts, num_models_str
252
+ return list(dataframes.values()) + list(winner_texts.values()) + [num_models_str]
253
 
254
 
255
  with gr.Blocks(css=css) as demo:
256
  with open("texts/heading.md") as fp:
257
  gr.Markdown(fp.read())
258
+ num_models_md = gr.Markdown()
259
  with gr.Tabs(elem_classes="tab-buttons") as tabs:
260
  with gr.TabItem("🏅 Leaderboard"):
261
  all_gr_dfs = {}
 
304
  with open("texts/about.md") as fp:
305
  gr.Markdown(fp.read())
306
 
307
+ demo.load(refresh, outputs=list(all_gr_dfs.values()) + list(all_gr_winners.values()) + [num_models_md])
308
 
309
  scheduler = BackgroundScheduler()
310
  scheduler.add_job(func=backend_routine, trigger="interval", seconds=REFRESH_RATE, max_instances=1)