File size: 1,925 Bytes
889dea9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03c7cdd
889dea9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
"""Deploy FATHOM demo server to HuggingFace Streamlit Space.

Run: python scripts/deploy_demo_space.py
"""
from __future__ import annotations

import os
import sys
from pathlib import Path

# Force UTF-8 output on Windows
if sys.platform == "win32":
    import io
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")

HF_TOKEN = os.getenv("HF_TOKEN")
SPACE_NAME = "Pratham-math/fathom-demo"
REPO_ROOT = Path(__file__).parent.parent


def deploy():
    from huggingface_hub import HfApi

    api = HfApi(token=HF_TOKEN)
    me = api.whoami()
    print(f"Logged in as: {me['name']}")

    # 1. Create Space (Streamlit SDK)
    print(f"Ensuring Space exists: {SPACE_NAME} ...")
    api.create_repo(
        repo_id=SPACE_NAME,
        repo_type="space",
        space_sdk="docker",
        private=False,
        exist_ok=True,
    )
    print("Space ready.")

    # 2. Collect files to upload
    uploads = [
        (REPO_ROOT / "space_demo" / "app.py",  "app.py"),
        (REPO_ROOT / "space_demo" / "README.md",   "README.md"),
        (REPO_ROOT / "space_demo" / "requirements.txt",        "requirements.txt"),
    ]

    print(f"Uploading {len(uploads)} files...")
    for local, remote in uploads:
        if local.exists():
            api.upload_file(
                path_or_fileobj=str(local),
                path_in_repo=remote,
                repo_id=SPACE_NAME,
                repo_type="space",
                commit_message=f"Deploy demo: {remote}",
            )
            print(f"  OK  {remote}")
        else:
            print(f"  SKIP (missing): {local}")

    hf_url = f"https://huggingface.co/spaces/{SPACE_NAME}"
    space_url = f"https://Pratham-math-fathom-demo.hf.space"

    print("=" * 60)
    print("Deploy complete!")
    print(f"  HF Space : {hf_url}")
    print(f"  App URL  : {space_url}")
    print("=" * 60)

if __name__ == "__main__":
    deploy()