Spaces:
Running
Running
Commit
•
8a91492
1
Parent(s):
608184c
Schedule Space restart to update list of models
Browse files- app.py +7 -0
- requirements.txt +1 -1
- src/hub.py +9 -1
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
import src.constants as constants
|
4 |
from src.details import (
|
@@ -12,6 +13,7 @@ from src.details import (
|
|
12 |
update_task_description_component,
|
13 |
)
|
14 |
from src.env_impact import plot_env_impact
|
|
|
15 |
from src.model_tree import load_model_tree
|
16 |
from src.results import (
|
17 |
clear_results,
|
@@ -298,4 +300,9 @@ with gr.Blocks(fill_height=True, fill_width=True) as demo:
|
|
298 |
],
|
299 |
)
|
300 |
|
|
|
|
|
|
|
|
|
|
|
301 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
3 |
|
4 |
import src.constants as constants
|
5 |
from src.details import (
|
|
|
13 |
update_task_description_component,
|
14 |
)
|
15 |
from src.env_impact import plot_env_impact
|
16 |
+
from src.hub import restart_space
|
17 |
from src.model_tree import load_model_tree
|
18 |
from src.results import (
|
19 |
clear_results,
|
|
|
300 |
],
|
301 |
)
|
302 |
|
303 |
+
# Start scheduler
|
304 |
+
scheduler = BackgroundScheduler()
|
305 |
+
scheduler.add_job(restart_space, "interval", hours=1) # Restart every 1h
|
306 |
+
scheduler.start()
|
307 |
+
|
308 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
|
|
1 |
plotly
|
2 |
-
|
|
|
1 |
+
apscheduler
|
2 |
plotly
|
|
src/hub.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import asyncio
|
2 |
import io
|
3 |
import json
|
|
|
4 |
|
5 |
import httpx
|
6 |
-
from huggingface_hub import HfFileSystem, ModelCard, hf_hub_url
|
7 |
from huggingface_hub.utils import build_hf_headers
|
8 |
|
9 |
import src.constants as constants
|
@@ -39,6 +40,7 @@ class Client:
|
|
39 |
return
|
40 |
|
41 |
|
|
|
42 |
client = Client()
|
43 |
fs = HfFileSystem()
|
44 |
|
@@ -87,3 +89,9 @@ async def list_models(filtering=None):
|
|
87 |
if r is None:
|
88 |
return
|
89 |
return r.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import asyncio
|
2 |
import io
|
3 |
import json
|
4 |
+
import os
|
5 |
|
6 |
import httpx
|
7 |
+
from huggingface_hub import HfApi, HfFileSystem, ModelCard, hf_hub_url
|
8 |
from huggingface_hub.utils import build_hf_headers
|
9 |
|
10 |
import src.constants as constants
|
|
|
40 |
return
|
41 |
|
42 |
|
43 |
+
api = HfApi()
|
44 |
client = Client()
|
45 |
fs = HfFileSystem()
|
46 |
|
|
|
89 |
if r is None:
|
90 |
return
|
91 |
return r.json()
|
92 |
+
|
93 |
+
|
94 |
+
def restart_space():
|
95 |
+
space_id = os.getenv("SPACE_ID")
|
96 |
+
if space_id:
|
97 |
+
api.restart_space(repo_id=space_id, token=os.getenv("HF_TOKEN"))
|