-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor restart_space script to accept space and token as command li…
…ne arguments
- Loading branch information
1 parent
86af0e3
commit bcdc329
Showing
2 changed files
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
import os | ||
import argparse | ||
|
||
from huggingface_hub import HfApi, list_models | ||
from rich import print | ||
|
||
# Use root method | ||
models = list_models() | ||
|
||
args = argparse.ArgumentParser(description="Restart a space in the Hugging Face Hub.") | ||
args.add_argument("--space", type=str, help="The space to restart.") | ||
args.add_argument("--token", type=str, help="The Hugging Face API token.") | ||
|
||
parsed_args = args.parse_args() | ||
|
||
space = parsed_args.space | ||
|
||
if not space: | ||
print("Please provide a space to restart.") | ||
exit() | ||
|
||
if not parsed_args.api_token: | ||
print("Please provide an API token.") | ||
exit() | ||
|
||
# Or configure a HfApi client | ||
hf_api = HfApi( | ||
endpoint="https://huggingface.co", # Can be a Private Hub endpoint. | ||
token=os.getenv("HUGGINFACE_API_TOKEN"), | ||
token=parsed_args.token, | ||
) | ||
|
||
space_runtime = hf_api.restart_space("Langflow/Langflow-Preview", factory_reboot=True) | ||
space_runtime = hf_api.restart_space(space, factory_reboot=True) | ||
print(space_runtime) |