File size: 1,400 Bytes
7da2ecb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Upload the release using resumable, multi-commit Hugging Face Hub uploads."""

from __future__ import annotations

import argparse
from pathlib import Path

from huggingface_hub import HfApi


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--root", required=True, type=Path)
    parser.add_argument("--repo-id", required=True)
    parser.add_argument("--include", action="append", default=None, help="Glob to upload; repeat as needed")
    parser.add_argument("--workers", type=int, default=None)
    parser.add_argument("--private", action="store_true", help="Create a private repository instead of public")
    args = parser.parse_args()

    root = args.root.resolve()
    if not (root / "MANIFEST.sha256").is_file():
        raise FileNotFoundError(
            "MANIFEST.sha256 is missing; run code/validation/run/verify_release.sh first"
        )
    api = HfApi()
    api.create_repo(
        repo_id=args.repo_id,
        repo_type="model",
        private=bool(args.private),
        exist_ok=True,
    )
    api.upload_large_folder(
        repo_id=args.repo_id,
        repo_type="model",
        folder_path=root,
        allow_patterns=args.include,
        ignore_patterns=["**/*.partial", "**/__pycache__/**", ".git/**"],
        num_workers=args.workers,
    )


if __name__ == "__main__":
    main()