#!/usr/bin/env python3 """ Push zindango-slm to Hugging Face Hub. Usage: python scripts/push_to_hub.py [--model-dir PATH] [--repo-id USERNAME/zindango-slm] Requires: huggingface-cli login (or HF_TOKEN env) """ import argparse from pathlib import Path from huggingface_hub import HfApi, create_repo, upload_folder def main(): parser = argparse.ArgumentParser(description="Push zindango-slm to Hugging Face Hub") parser.add_argument( "--model-dir", type=str, default="outputs/zindango-slm-20260215_124754", help="Local model directory to upload", ) parser.add_argument( "--repo-id", type=str, default=None, help="Hub repo ID (username/zindango-slm). Default: infer from login", ) parser.add_argument( "--private", action="store_true", help="Create private repository", ) parser.add_argument( "--skip-create", action="store_true", help="Skip create_repo (use if repo already exists or create manually at https://huggingface.co/new)", ) args = parser.parse_args() model_dir = Path(args.model_dir) if not model_dir.exists(): raise SystemExit(f"Model directory not found: {model_dir}") api = HfApi() try: user = api.whoami() username = user["name"] except Exception as e: raise SystemExit( f"Not logged in to Hugging Face. Run: huggingface-cli login\nError: {e}" ) repo_id = args.repo_id or f"{username}/zindango-slm" print(f"Uploading to https://huggingface.co/{repo_id}") # Create repo if needed (skip if --skip-create or 403) if not args.skip_create: try: create_repo(repo_id, repo_type="model", private=args.private, exist_ok=True) except Exception as e: err = str(e).lower() if "403" in err or "forbidden" in err or "rights" in err: print("Note: Could not create repo (check token write access).") print("Create it manually at: https://huggingface.co/new") print("Then run with: --skip-create") raise if "already exists" not in err and "409" not in err: raise # Exclude checkpoint subdir and training artifacts ignore_patterns = ["checkpoint-*", "training_args.bin", "*.pt", ".git*"] upload_folder( folder_path=str(model_dir), repo_id=repo_id, repo_type="model", ignore_patterns=ignore_patterns, commit_message="Upload zindango-slm: SFT for Zindango (English-only)", ) print(f"Done. Model: https://huggingface.co/{repo_id}") if __name__ == "__main__": main()