Spaces:
Running
Running
Download deploy/hf/publish.py from Aynkhn/WorkPilot-AI: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/spaces/Aynkhn/WorkPilot-AI/resolve/main/deploy/hf/publish.py
- Command line
-
hf download hf://spaces/Aynkhn/WorkPilot-AI/deploy/hf/publish.py
-
curl -L -o publish.py https://huggingface.co/spaces/Aynkhn/WorkPilot-AI/resolve/main/deploy/hf/publish.py
1.78 kB
| """Upload an assembled Space folder to Hugging Face and copy model settings to it. | |
| HF_TOKEN=... HF_SPACE=<user>/<space> python deploy/hf/publish.py <folder> | |
| Used by .github/workflows/hf-space.yml. Model keys present in the environment | |
| (GOOGLE_API_KEY, GROQ_API_KEY, ANTHROPIC_API_KEY, OPENAI_API_KEY) become Space *secrets*; | |
| WP_MODEL_* tiers become Space *variables*. Nothing secret is written into the Space files. | |
| The upload replaces the Space's files (``delete_patterns="*"``); its git history keeps the | |
| previous version. | |
| """ | |
| from __future__ import annotations | |
| import os | |
| import sys | |
| SECRETS = ("GOOGLE_API_KEY", "GROQ_API_KEY", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", "WP_JWT_SECRET") | |
| VARIABLES = ("WP_MODEL_ROUTER", "WP_MODEL_WORKER", "WP_MODEL_PLANNER") | |
| def main(folder: str) -> int: | |
| from huggingface_hub import HfApi | |
| token, space = os.environ.get("HF_TOKEN"), os.environ.get("HF_SPACE") | |
| if not token or not space: | |
| print("set HF_TOKEN and HF_SPACE", file=sys.stderr) | |
| return 2 | |
| api = HfApi(token=token) | |
| for name in SECRETS: | |
| if os.environ.get(name): | |
| api.add_space_secret(space, name, os.environ[name]) | |
| print(f"space secret set: {name}") | |
| for name in VARIABLES: | |
| if os.environ.get(name): | |
| api.add_space_variable(space, name, os.environ[name]) | |
| print(f"space variable set: {name}={os.environ[name]}") | |
| api.upload_folder( | |
| repo_id=space, | |
| repo_type="space", | |
| folder_path=folder, | |
| delete_patterns="*", | |
| commit_message="Deploy WorkPilot demo", | |
| ) | |
| print(f"uploaded {folder} to https://huggingface.co/spaces/{space}") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else "space")) | |