File size: 1,875 Bytes
bbddeaa | 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #!/usr/bin/env python3
"""Publish Brettapps/trifecta-bro-v1 to the HuggingFace Hub.
Requires a VALID HuggingFace token, supplied via:
- HF_ACCESS_TOKEN / HF_TOKEN env var, or
- the cached `huggingface_hub` credentials (hf auth login)
This script ONLY uploads; it does not build the package (build is done via
save_artifact + the committed source files). Run after `hf auth login` succeeds.
Usage:
python push.py # uses cached/ENV token
HF_ACCESS_TOKEN=hf_xxx python push.py
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
from huggingface_hub import HfApi, create_repo
REPO_ID = "Brettapps/trifecta-bro-v1"
REPO_TYPE = "model"
LOCAL_DIR = Path(__file__).resolve().parents[0]
ARTIFACT_DIR = LOCAL_DIR / "model_artifacts"
def main() -> int:
token = os.environ.get("HF_ACCESS_TOKEN") or os.environ.get("HF_TOKEN")
api = HfApi(token=token)
# Fail fast with a clear message if the token is invalid/expired.
try:
me = api.whoami()
print(f"Authenticated as: {me.get('name') or me.get('id')}")
except Exception as exc: # noqa: BLE001
print(f"ERROR: HuggingFace authentication failed: {exc}")
print("Fix: run `hf auth login` with a valid token, or set HF_ACCESS_TOKEN.")
return 1
# Ensure the repo exists under the authenticated namespace.
create_repo(
repo_id=REPO_ID,
repo_type=REPO_TYPE,
token=token,
exist_ok=True,
)
print(f"Uploading {LOCAL_DIR} -> {REPO_ID}")
api.upload_folder(
folder_path=str(LOCAL_DIR),
repo_id=REPO_ID,
repo_type=REPO_TYPE,
commit_message="Add Brettapps/trifecta-bro/v1 v1.0.0 predictor",
token=token,
)
print(f"DONE: https://huggingface.co/{REPO_ID}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
|