incident-commander / scripts /deploy_to_space.py
GlitchGhost's picture
Deploy IncidentCommander OpenEnv
e09df37 verified
Raw
History Blame Contribute Delete
2.45 kB
"""Deploy the IncidentCommander environment to a Hugging Face Space.
Uses the ``huggingface_hub`` Python API instead of ``git`` so this works on
Windows / macOS / Linux without requiring the git CLI.
Required env vars:
HF_TOKEN Hugging Face access token with `write` scope.
SPACE_REPO_ID e.g. ``alice/incident-commander``.
Optional:
SPACE_PRIVATE ``true`` to create a private Space (default: false).
Usage (PowerShell)::
$env:HF_TOKEN = "hf_..."
$env:SPACE_REPO_ID = "alice/incident-commander"
python scripts/deploy_to_space.py
The script uploads the project root (excluding venv / build artifacts /
results) and HF's Space runner builds the Dockerfile automatically.
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
IGNORE_PATTERNS = [
".venv",
".venv/*",
".git",
".git/*",
"__pycache__",
"*/__pycache__/*",
"*.pyc",
".pytest_cache",
".pytest_cache/*",
"build",
"build/*",
"dist",
"dist/*",
"*.egg-info",
"*.egg-info/*",
"results",
"results/*",
".ipynb_checkpoints",
"*/.ipynb_checkpoints/*",
".coverage",
"coverage.xml",
]
def main() -> int:
token = os.environ.get("HF_TOKEN")
repo_id = os.environ.get("SPACE_REPO_ID")
private = os.environ.get("SPACE_PRIVATE", "").lower() in {"1", "true", "yes"}
if not token:
print("ERROR: HF_TOKEN is not set", file=sys.stderr)
return 2
if not repo_id:
print("ERROR: SPACE_REPO_ID is not set", file=sys.stderr)
return 2
from huggingface_hub import HfApi
api = HfApi(token=token)
print(f"Ensuring Space {repo_id} exists (private={private}) ...")
api.create_repo(
repo_id=repo_id,
repo_type="space",
space_sdk="docker",
private=private,
exist_ok=True,
)
print(f"Uploading {ROOT} to {repo_id} ...")
commit = api.upload_folder(
folder_path=str(ROOT),
repo_id=repo_id,
repo_type="space",
ignore_patterns=IGNORE_PATTERNS,
commit_message="Deploy IncidentCommander OpenEnv",
)
print(f"Uploaded. Commit: {commit}")
print(f"Space URL: https://huggingface.co/spaces/{repo_id}")
print("HF will now build the Dockerfile. Watch the build log on the Space page.")
return 0
if __name__ == "__main__":
raise SystemExit(main())