File size: 1,161 Bytes
f6bb5b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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()