andrewrreed HF staff commited on
Commit
03480fc
1 Parent(s): d2967a8

add automated scheduler for daily restarts

Browse files
Files changed (2) hide show
  1. app.py +18 -0
  2. requirements.txt +2 -1
app.py CHANGED
@@ -3,6 +3,9 @@ import pickle
3
  import pandas as pd
4
  import gradio as gr
5
  import plotly.express as px
 
 
 
6
 
7
  from utils import (
8
  KEY_TO_CATEGORY_NAME,
@@ -13,6 +16,21 @@ from utils import (
13
  format_data,
14
  )
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  ###################
17
  ### Load Data
18
  ###################
 
3
  import pandas as pd
4
  import gradio as gr
5
  import plotly.express as px
6
+ from datetime import datetime
7
+ from huggingface_hub import HfApi
8
+ from apscheduler.schedulers.background import BackgroundScheduler
9
 
10
  from utils import (
11
  KEY_TO_CATEGORY_NAME,
 
16
  format_data,
17
  )
18
 
19
+ ###################
20
+ ### Initialize scheduler
21
+ ###################
22
+
23
+
24
+ def restart_space():
25
+ HfApi().restart_space(repo_id="andrewrreed/closed-vs-open-arena-elo")
26
+ print(f"Space restarted on {datetime.now()}")
27
+
28
+
29
+ # restart the space every day at 9am
30
+ scheduler = BackgroundScheduler()
31
+ scheduler.add_job(restart_space, "cron", day_of_week="mon-sun", hour=9, minute=0)
32
+ scheduler.start()
33
+
34
  ###################
35
  ### Load Data
36
  ###################
requirements.txt CHANGED
@@ -2,4 +2,5 @@ huggingface_hub
2
  pandas
3
  plotly
4
  gradio
5
- statsmodels
 
 
2
  pandas
3
  plotly
4
  gradio
5
+ statsmodels
6
+ apscheduler