Weyaxi commited on
Commit
2f2f3ae
1 Parent(s): a2723b3

refresh instead of restart

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -18,6 +18,8 @@ from gradio_space_ci import enable_space_ci
18
  enable_space_ci()
19
 
20
  HF_TOKEN = os.getenv('HF_TOKEN')
 
 
21
 
22
  api = HfApi()
23
  fs = HfFileSystem()
@@ -27,9 +29,17 @@ finished_models = get_datas(data)
27
  df = pd.DataFrame(finished_models)
28
 
29
 
30
- def restart_space():
31
- time.sleep(3600)
32
- api.restart_space(repo_id="Weyaxi/leaderboard-results-to-modelcard", token=HF_TOKEN)
 
 
 
 
 
 
 
 
33
 
34
 
35
  def search(df, value):
@@ -242,5 +252,5 @@ with gr.Blocks() as demo:
242
  submit_btn = gr.Button("Submit", variant="primary")
243
  submit_btn.click(commit, model_id, output)
244
 
245
- threading.Thread(target=restart_space).start()
246
  demo.launch()
 
18
  enable_space_ci()
19
 
20
  HF_TOKEN = os.getenv('HF_TOKEN')
21
+ BOT_HF_TOKEN = os.getenv('BOT_HF_TOKEN')
22
+
23
 
24
  api = HfApi()
25
  fs = HfFileSystem()
 
29
  df = pd.DataFrame(finished_models)
30
 
31
 
32
+ def refresh(how_much=3600): # default to 1 hour
33
+ global data, finished_models, df
34
+ time.sleep(how_much)
35
+
36
+ try:
37
+ data = get_json_format_data()
38
+ finished_models = get_datas(data)
39
+ df = pd.DataFrame(finished_models)
40
+ except Exception as e:
41
+ print(f"Error while scraping leaderboard, trying again... {e]")
42
+ refresh(600) # 10 minutes if any error happens
43
 
44
 
45
  def search(df, value):
 
252
  submit_btn = gr.Button("Submit", variant="primary")
253
  submit_btn.click(commit, model_id, output)
254
 
255
+ threading.Thread(target=refresh).start()
256
  demo.launch()