File size: 2,035 Bytes
9ea491e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""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()