Spaces:
Build error
Build error
Upload 3 files
Browse files- README.md +13 -12
- app.py +42 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Space Waker
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Space Waker
|
| 3 |
+
emoji: ⏰
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.40.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 7 |
+
HF_USER = os.environ.get("HF_USER")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def wakeup_spaces(username: str, hf_token: str="", is_private=True, progress=gr.Progress(track_tqdm=True)):
|
| 11 |
+
try:
|
| 12 |
+
api = HfApi(token=hf_token if hf_token else HF_TOKEN)
|
| 13 |
+
space_infos = api.list_spaces(author=username)
|
| 14 |
+
spaces = []
|
| 15 |
+
for s in space_infos:
|
| 16 |
+
if s.private and not is_private: continue
|
| 17 |
+
spaces.append(s.id)
|
| 18 |
+
for s in spaces:
|
| 19 |
+
if api.get_space_runtime(repo_id=s).stage in ("RUNNING", "APP_STARTING", "BUILDING"):
|
| 20 |
+
print(f"'{s}' is running.")
|
| 21 |
+
progress(0, desc=f"'{s}' is running.")
|
| 22 |
+
else:
|
| 23 |
+
print(f"'{s}' isn't running. Restarting...")
|
| 24 |
+
progress(0, desc=f"'{s}' isn't running. Restarting...")
|
| 25 |
+
api.restart_space(repo_id=s)
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"Error: {e}")
|
| 28 |
+
raise gr.Error(f"Error: {e}")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
with gr.Row():
|
| 33 |
+
username = gr.Textbox(label="HF Username", value=HF_USER, lines=1)
|
| 34 |
+
token = gr.Textbox(label="HF Write Token", value="", lines=1)
|
| 35 |
+
is_private = gr.Checkbox(label="Apply to private space", value=True)
|
| 36 |
+
run_button = gr.Button("Wake up spaces", variant="primary")
|
| 37 |
+
info_md = gr.Markdown("<br><br><br>")
|
| 38 |
+
|
| 39 |
+
run_button.click(wakeup_spaces, [username, is_private], [info_md])
|
| 40 |
+
|
| 41 |
+
demo.launch()
|
| 42 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub
|