fathom-code / scripts /deploy_demo_space.py
23f2002275
Update demo space
03c7cdd
Raw
History Blame Contribute Delete
1.93 kB
"""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()