#!/usr/bin/env python3 """Publish the current HVCE release folder to a public Hugging Face Hub repo. The write token is read from HF_TOKEN. It is never written to project files. """ from __future__ import annotations import os import sys from pathlib import Path from huggingface_hub import HfApi, create_repo, upload_folder RELEASE_TAG = "v4.0.0-OmniCrown" DEFAULT_REPO_NAME = "heaven-vector-compression-engine" def main() -> int: token = os.environ.get("HF_TOKEN", "").strip() if not token: print("ERROR: HF_TOKEN is not set. Use PUBLISH_TO_HUGGINGFACE.bat.", file=sys.stderr) return 2 repo_name = os.environ.get("HVCE_REPO_NAME", DEFAULT_REPO_NAME).strip() or DEFAULT_REPO_NAME api = HfApi(token=token) who = api.whoami() username = who.get("name") or who.get("fullname") if not username: print("ERROR: Could not determine the authenticated Hugging Face username.", file=sys.stderr) return 3 repo_id = f"{username}/{repo_name}" root = Path(__file__).resolve().parent print(f"Authenticated as: {username}") print(f"Target repository: {repo_id}") print("Visibility: public") create_repo( repo_id=repo_id, repo_type="model", private=False, exist_ok=True, token=token, ) # Explicitly ensure public visibility even when reusing an existing repo. try: api.update_repo_settings(repo_id=repo_id, repo_type="model", private=False) except Exception as exc: print(f"Warning: could not explicitly update visibility: {exc}") ignore_patterns = [ ".git/*", ".git/**", "__pycache__/*", "**/__pycache__/*", "*.pyc", "*.pyo", ".pytest_cache/*", ".pytest_cache/**", "benchmarks/local_run/*", "benchmarks/local_run/**", "upload_work/*", "upload_work/**" ] upload_folder( folder_path=str(root), repo_id=repo_id, repo_type="model", token=token, commit_message="HVCE v4.0.0 OmniCrown — very early public research prototype", ignore_patterns=ignore_patterns, ) try: api.create_tag( repo_id=repo_id, repo_type="model", tag=RELEASE_TAG, tag_message="HVCE v4.0.0 OmniCrown public research prototype", ) print(f"Created tag: {RELEASE_TAG}") except Exception as exc: print(f"Tag note: {exc}") url = f"https://huggingface.co/{repo_id}" print("\nPublication complete:") print(url) print("\nReminder: this repository is intentionally framed as a very early prototype; it may compress poorly.") return 0 if __name__ == "__main__": raise SystemExit(main())