File size: 997 Bytes
1b690c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import os
from pathlib import Path

from huggingface_hub import HfApi


SPACE_ID = os.getenv("HF_SPACE_ID", "binzhango/hf-build-small-hackathon")
HF_TOKEN = os.getenv("HF_TOKEN")
ROOT = Path(__file__).resolve().parents[1]

IGNORE_PATTERNS = [
    ".git/*",
    ".github/*",
    ".venv/*",
    "__pycache__/*",
    "*.pyc",
    ".pytest_cache/*",
    ".ruff_cache/*",
    ".mypy_cache/*",
    "uv.lock",
]


def main() -> None:
    if not HF_TOKEN:
        raise SystemExit("HF_TOKEN is required to deploy to Hugging Face Spaces.")

    api = HfApi(token=HF_TOKEN)
    api.create_repo(
        repo_id=SPACE_ID,
        repo_type="space",
        space_sdk="gradio",
        exist_ok=True,
    )
    api.upload_folder(
        folder_path=ROOT,
        repo_id=SPACE_ID,
        repo_type="space",
        token=HF_TOKEN,
        commit_message="Deploy from GitHub Actions",
        ignore_patterns=IGNORE_PATTERNS,
    )


if __name__ == "__main__":
    main()