File size: 1,684 Bytes
4d68493 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | """Tiny helper for deploying the app to a Hugging Face Space.
Usage (PowerShell, from the project root):
# one-time
pip install "huggingface_hub[cli]"
huggingface-cli login
# create the Space (do this once)
huggingface-cli repo create us-flow-scanner --type space --space-sdk gradio
# initialise git in this folder and push
git init
git checkout -b main
git add .
git commit -m "Initial deploy"
git remote add space https://huggingface.co/spaces/<your-username>/us-flow-scanner
git push --set-upstream space main
# subsequent updates
git add .
git commit -m "..."
git push space main
"""
from __future__ import annotations
import os
import subprocess
import sys
def _run(cmd: list[str]) -> None:
print(f"\n$ {' '.join(cmd)}")
subprocess.run(cmd, check=False)
def main() -> None:
username = os.environ.get("HF_USERNAME")
space = os.environ.get("HF_SPACE_NAME", "us-flow-scanner")
if not username:
print("Set HF_USERNAME env var (your HF handle).", file=sys.stderr)
sys.exit(1)
repo_id = f"{username}/{space}"
_run(["huggingface-cli", "repo", "create", space, "--type", "space",
"--space-sdk", "gradio", "--exist-ok"])
if not os.path.isdir(".git"):
_run(["git", "init"])
_run(["git", "checkout", "-b", "main"])
_run(["git", "add", "."])
_run(["git", "commit", "-m", "Deploy to HF Space", "--allow-empty"])
remote = f"https://huggingface.co/spaces/{repo_id}"
_run(["git", "remote", "add", "space", remote])
_run(["git", "push", "--set-upstream", "space", "main", "--force"])
if __name__ == "__main__":
main()
|