email-assistant / deploy.py
Brettapps's picture
Upload deploy.py with huggingface_hub
12ef073 verified
Raw History Blame Contribute Delete
1.07 kB
#!/usr/bin/env python3
"""Deploy Brettapps/email-assistant Static HF Space."""
from __future__ import annotations
import os
from pathlib import Path
from huggingface_hub import HfApi, create_repo, upload_folder
SPACE_ID = "Brettapps/email-assistant"
LOCAL_DIR = Path(__file__).resolve().parents[0]
def deploy() -> None:
token = os.environ.get("HF_ACCESS_TOKEN") or os.environ.get("HF_TOKEN")
if not token:
raise EnvironmentError("HF_ACCESS_TOKEN / HF_TOKEN required")
api = HfApi(token=token)
try:
api.whoami()
except Exception as exc:
print(f"HF auth failed: {exc}")
raise SystemExit(1)
create_repo(repo_id=SPACE_ID, repo_type="space", token=token, exist_ok=True, space_sdk="static")
print(f"Deploying {LOCAL_DIR} -> {SPACE_ID}")
upload_folder(folder_path=str(LOCAL_DIR), repo_id=SPACE_ID, repo_type="space",
commit_message="Email assistant v2: + image generation (FLUX)", token=token)
print(f"Done: https://huggingface.co/spaces/{SPACE_ID}")
if __name__ == "__main__":
deploy()