"""Check the release and, with --yes, upload it to the Hugging Face Hub. Usage: python scripts/publish.py (checks only, uploads nothing) python scripts/publish.py --yes (creates the public repo and uploads) Requires `pip install huggingface_hub` and `hf auth login`. """ import argparse import json import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent IGNORE = ["_private/*", ".git/*", ".gitignore", "card/*", "**/__pycache__/*"] REQUIRED = ["README.md", "LICENSE", "NOTICE", "SHA256SUMS", "Modelfile", "template", "params", "Sagui-4B-IQ3_XXS.gguf", "mmproj-Sagui-4B-F16.gguf", "assets/banner.png"] def problems(cfg): found = [f"missing file: {name}" for name in REQUIRED if not (ROOT / name).exists()] if not any(cfg["donations"].values()): found.append("release.json: no donation link filled in") readme = (ROOT / "README.md").read_text(encoding="utf-8") if (ROOT / "README.md").exists() else "" if "@@" in readme: found.append("README.md has unrendered placeholders: run scripts/render_card.py") return found def main(): ap = argparse.ArgumentParser() ap.add_argument("--yes", action="store_true", help="really create the public repo and upload") args = ap.parse_args() cfg = json.loads((ROOT / "release.json").read_text(encoding="utf-8")) repo_id = f"{cfg['hf_namespace']}/{cfg['repo_name']}" found = problems(cfg) for problem in found: print("BLOCKED:", problem) if found: sys.exit(1) print(f"OK: ready to publish {repo_id}") if not args.yes: print("Nothing uploaded. Run again with --yes to publish.") return from huggingface_hub import HfApi api = HfApi() api.create_repo(repo_id, repo_type="model", exist_ok=True) api.upload_folder(repo_id=repo_id, folder_path=ROOT, ignore_patterns=IGNORE, commit_message="Release Sagui-4B") print(f"https://huggingface.co/{repo_id}") if __name__ == "__main__": main()