#!/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())