patrickvonplaten osanseviero commited on
Commit
53d8831
1 Parent(s): 8b95278

Refresh leaderboard every 20 minutes (#2)

Browse files

- Restart every 20 mins (650c7423191c22f3b96f8ca397486093f3cdf758)


Co-authored-by: Omar Sanseviero <osanseviero@users.noreply.huggingface.co>

Files changed (2) hide show
  1. app.py +16 -5
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,9 +1,16 @@
1
- from datasets import load_dataset
2
- from collections import Counter, defaultdict
3
- import pandas as pd
4
- from huggingface_hub import list_datasets
5
  import os
 
6
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
7
 
8
  parti_prompt_results = []
9
  ORG = "diffusers-parti-prompts"
@@ -176,6 +183,10 @@ with gr.Blocks() as demo:
176
  with gr.Row():
177
  refresh_button = gr.Button("Refresh")
178
  refresh_button.click(refresh, inputs=[], outputs=[num_submissions, main_dataframe, cat_dataframe, chal_dataframe])
179
- demo.load(refresh, inputs=[], outputs=[num_submissions, main_dataframe, cat_dataframe, chal_dataframe])
 
 
 
 
180
 
181
  demo.launch()
 
 
 
 
 
1
  import os
2
+
3
  import gradio as gr
4
+ import pandas as pd
5
+
6
+ from apscheduler.schedulers.background import BackgroundScheduler
7
+ from collections import Counter, defaultdict
8
+ from datasets import load_dataset
9
+ from huggingface_hub import HfApi, list_datasets
10
+
11
+ api = HfApi(token=os.environ.get("HF_TOKEN", None))
12
+ def restart_space():
13
+ api.restart_space(repo_id="OpenGenAI/parti-prompts-leaderboard")
14
 
15
  parti_prompt_results = []
16
  ORG = "diffusers-parti-prompts"
 
183
  with gr.Row():
184
  refresh_button = gr.Button("Refresh")
185
  refresh_button.click(refresh, inputs=[], outputs=[num_submissions, main_dataframe, cat_dataframe, chal_dataframe])
186
+
187
+ # Restart space every 20 minutes
188
+ scheduler = BackgroundScheduler()
189
+ scheduler.add_job(restart_space, 'interval', seconds=3600)
190
+ scheduler.start()
191
 
192
  demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
 
1
  datasets
2
  pandas
 
1
+ apscheduler
2
  datasets
3
  pandas