Spaces:
Running
Running
Download tools/deploy_space.py from EHS-Studio/techglass-mint: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/spaces/EHS-Studio/techglass-mint/resolve/main/tools/deploy_space.py
- Command line
-
hf download hf://spaces/EHS-Studio/techglass-mint/tools/deploy_space.py
-
curl -L -o deploy_space.py https://huggingface.co/spaces/EHS-Studio/techglass-mint/resolve/main/tools/deploy_space.py
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() | |