# -*- coding: utf-8 -*-
"""Publish the Sparse Model Nexus adapter bundle to the Hugging Face Hub.

Requires auth: set HF_TOKEN or run `hf auth login` first.
Usage: python publish_to_hf.py <namespace/repo-id>
"""
import os, sys
from huggingface_hub import HfApi, whoami

def main():
    repo_id = sys.argv[1] if len(sys.argv) > 1 else None
    api = HfApi()
    who = whoami()  # raises if not authenticated
    user = who["name"]
    if repo_id is None:
        repo_id = f"{user}/sparse-model-nexus"
    print(f"Authenticated as {user}; target repo: {repo_id}")

    here = os.path.dirname(os.path.abspath(__file__))
    api.create_repo(repo_id, repo_type="model", exist_ok=True)
    # Upload the model card, algebra package, adapters, and demo transcript.
    api.upload_folder(
        repo_id=repo_id,
        repo_type="model",
        folder_path=here,
        ignore_patterns=["__pycache__/*", "*.pyc"],
        commit_message="Sparse Model Nexus: 3 LoRA quanta + operator algebra + demo transcript",
    )
    print(f"Published: https://huggingface.co/{repo_id}")

if __name__ == "__main__":
    main()
