#!/usr/bin/env python3 """Restart a HuggingFace Space via API. Requires HF token with write access. Usage: python3 restart_space.py [OWNER/REPO_NAME] Default: hf4uwho/Pocket-TTS """ import sys, os from huggingface_hub import HfApi repo_id = sys.argv[1] if len(sys.argv) > 1 else "hf4uwho/Pocket-TTS" token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") if not token: # Try reading from default token path token_path = os.path.expanduser("~/.cache/huggingface/token") if os.path.exists(token_path): token = open(token_path).read().strip() if not token: print("ERROR: No HF token found. Set HF_TOKEN env var or login with `huggingface-cli login`") sys.exit(1) api = HfApi(token=token) try: api.restart_space(repo_id=repo_id) print(f"Space {repo_id} restart initiated") except Exception as e: print(f"ERROR restarting space: {e}") sys.exit(1)