Skip to content

Commit bcdc329

Browse files
committed
Refactor restart_space script to accept space and token as command line arguments
1 parent 86af0e3 commit bcdc329

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

.github/workflows/docker-build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,4 @@ jobs:
100100
101101
- name: Restart HuggingFace Spaces Build
102102
run: |
103-
poetry run python ./scripts/factory_restart_space.py
104-
env:
105-
HUGGINGFACE_API_TOKEN: ${{ secrets.HUGGINGFACE_API_TOKEN }}
103+
poetry run python ./scripts/factory_restart_space.py --space "Langflow/Langflow-Preview" --token ${{ secrets.HUGGINGFACE_API_TOKEN }}

scripts/factory_restart_space.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
import os
1+
import argparse
22

33
from huggingface_hub import HfApi, list_models
44
from rich import print
55

66
# Use root method
77
models = list_models()
88

9+
args = argparse.ArgumentParser(description="Restart a space in the Hugging Face Hub.")
10+
args.add_argument("--space", type=str, help="The space to restart.")
11+
args.add_argument("--token", type=str, help="The Hugging Face API token.")
12+
13+
parsed_args = args.parse_args()
14+
15+
space = parsed_args.space
16+
17+
if not space:
18+
print("Please provide a space to restart.")
19+
exit()
20+
21+
if not parsed_args.api_token:
22+
print("Please provide an API token.")
23+
exit()
24+
925
# Or configure a HfApi client
1026
hf_api = HfApi(
1127
endpoint="https://huggingface.co", # Can be a Private Hub endpoint.
12-
token=os.getenv("HUGGINFACE_API_TOKEN"),
28+
token=parsed_args.token,
1329
)
1430

15-
space_runtime = hf_api.restart_space("Langflow/Langflow-Preview", factory_reboot=True)
31+
space_runtime = hf_api.restart_space(space, factory_reboot=True)
1632
print(space_runtime)

0 commit comments

Comments
 (0)