techglass-mint / tools /deploy_space.py
EHS-Studio's picture
Add the Vercel deploy script and share the zip builder
58bf71d verified
Raw History Blame Contribute Delete
2.37 kB
#!/usr/bin/env python3
"""Push this folder to the Hugging Face Space, with a fresh download zip.
Needs huggingface_hub (pip install huggingface_hub). The token comes from $HF_TOKEN or from
~/Dokumente/tokens/HF token, and is never written anywhere.
Usage: python3 tools/deploy_space.py ["commit message"]
"""
import os
import re
import shutil
import sys
import tempfile
import zipfile
from pathlib import Path
REPO = "EHS-Studio/techglass-mint"
ROOT = Path(__file__).resolve().parent.parent
SKIP = {"__pycache__", "menu-icon.svg", ".claude", ".git"}
APP_FILES = ["tgcore.py", "studio.py", "templates", "fx", "icon.svg", "install.sh", "README.md", "LICENSE", "tools"]
def token():
if os.environ.get("HF_TOKEN"):
return os.environ["HF_TOKEN"]
text = (Path.home() / "Dokumente/tokens/HF token").read_text()
return re.search(r"hf_[A-Za-z0-9]+", text).group(0)
def build_zip(dest):
readme = re.sub(r"\A---\n.*?\n---\n+", "", (ROOT / "README.md").read_text(), flags=re.S)
with zipfile.ZipFile(dest, "w", zipfile.ZIP_DEFLATED) as z:
for name in APP_FILES:
src = ROOT / name
paths = [src] if src.is_file() else [p for p in src.rglob("*") if p.is_file()]
for p in paths:
if SKIP & set(p.relative_to(ROOT).parts):
continue
arc = "techglass-mint/" + str(p.relative_to(ROOT))
if p.name == "README.md" and p.parent == ROOT:
z.writestr(arc, readme)
else:
info = zipfile.ZipInfo.from_file(p, arc) # keeps install.sh executable
z.writestr(info, p.read_bytes())
def main():
from huggingface_hub import HfApi
message = sys.argv[1] if len(sys.argv) > 1 else "Update TechGlass Mint"
with tempfile.TemporaryDirectory() as tmp:
stage = Path(tmp) / "stage"
shutil.copytree(ROOT, stage, ignore=lambda d, names: [n for n in names if n in SKIP or n.endswith(".pyc")])
build_zip(stage / "techglass-mint.zip")
api = HfApi(token=token())
api.create_repo(REPO, repo_type="space", space_sdk="static", exist_ok=True)
api.upload_folder(folder_path=str(stage), repo_id=REPO, repo_type="space", commit_message=message)
print(f"Pushed to https://huggingface.co/spaces/{REPO}")
if __name__ == "__main__":
main()