Brettapps's picture
Update FairDinkumPublishing ebook pipeline
f6bb5b8 verified
Raw
History Blame Contribute Delete
1.16 kB
#!/usr/bin/env python3
"""Deploy FairDinkumPublishing HF Space."""
from __future__ import annotations
import os
from pathlib import Path
from huggingface_hub import HfApi, create_repo, upload_folder
SPACE_ID = "Brettapps/FairDinkumPublishing"
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 is required")
api = HfApi(token=token)
try:
api.whoami()
except Exception as exc:
print(f"HF auth failed: {exc}")
print("Run: hf auth login --force")
raise SystemExit(1)
create_repo(repo_id=SPACE_ID, repo_type="space", token=token, exist_ok=True,
space_sdk="gradio")
print(f"Deploying {LOCAL_DIR} -> {SPACE_ID}")
upload_folder(
folder_path=str(LOCAL_DIR),
repo_id=SPACE_ID,
repo_type="space",
commit_message="Update FairDinkumPublishing ebook pipeline",
token=token,
)
print(f"Done: https://huggingface.co/spaces/{SPACE_ID}")
if __name__ == "__main__":
deploy()