File size: 2,160 Bytes
161d0a9
c9c35b3
 
161d0a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 alvations (Melon Lab)
"""Deploy this repo to a Hugging Face Docker Space.

Run from a machine with normal internet access (not the sandboxed web session,
whose network policy blocks huggingface.co):

    pip install "huggingface_hub>=0.24"
    export HF_TOKEN=hf_...          # a *write* token from hf.co/settings/tokens
    python scripts/deploy_hf.py     # defaults to alvations/hallway8

Optionally pass a different target: python scripts/deploy_hf.py owner/space-name
"""

import os
import secrets
import sys

from huggingface_hub import HfApi, get_token

REPO_ID = sys.argv[1] if len(sys.argv) > 1 else "alvations/hallway8"
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def main() -> None:
    # Prefer an explicit HF_TOKEN, but fall back to a stored `hf auth login`
    # credential so this works without exporting anything.
    token = os.environ.get("HF_TOKEN") or get_token()
    if not token:
        sys.exit(
            "No token found. Run `hf auth login` or set HF_TOKEN to a write token."
        )

    api = HfApi(token=token)
    who = api.whoami()
    print(f"Authenticated as {who['name']}")

    url = api.create_repo(
        repo_id=REPO_ID, repo_type="space", space_sdk="docker", exist_ok=True
    )
    print(f"Space ready: {url}")

    # Stable session key so in-progress runs survive Space restarts.
    try:
        api.add_space_secret(REPO_ID, "SECRET_KEY", secrets.token_hex(32))
        print("SECRET_KEY secret set")
    except Exception as exc:  # non-fatal
        print(f"Could not set SECRET_KEY (set it manually if you want): {exc}")

    api.upload_folder(
        folder_path=ROOT,
        repo_id=REPO_ID,
        repo_type="space",
        commit_message="Deploy Hallway 8 (multi-arc memory game)",
        ignore_patterns=[
            ".git*", "**/__pycache__/**", "*.pyc", ".venv/**", "venv/**", ".env",
        ],
    )
    print(f"\nDone → https://huggingface.co/spaces/{REPO_ID}")
    print("The Space will build the Docker image and go live in a couple of minutes.")


if __name__ == "__main__":
    main()