File size: 2,271 Bytes
b2c2640
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""Create or update a Hugging Face **model** repo with this evaluation codebase.

This upload is **code and docs only** (no MiniCPM-o weights). HF allows model
repos to host auxiliary artifacts; use ``--private`` if you do not want the
scripts public.

Prerequisites::

    pip install huggingface_hub
    export HF_TOKEN=hf_...    # or: huggingface-cli login

Usage::

    cd MiniCPM-Evaluation
    python scripts/upload_to_hf_model.py --repo-id YourUsername/MiniCPM-Evaluation

Private repo::

    python scripts/upload_to_hf_model.py --repo-id YourUsername/MiniCPM-Evaluation --private
"""
from __future__ import annotations

import argparse
import sys
from pathlib import Path


def main() -> int:
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument(
        "--repo-id",
        required=True,
        help="HF repository id, e.g. username/MiniCPM-Evaluation",
    )
    p.add_argument(
        "--private",
        action="store_true",
        help="Create the repo as private (only for first create; ignored if repo exists).",
    )
    p.add_argument(
        "--token",
        default=None,
        help="HF token (default: HF_TOKEN env or cached huggingface-cli login).",
    )
    args = p.parse_args()

    root = Path(__file__).resolve().parent.parent
    if not (root / "README.md").is_file():
        print(f"error: unexpected layout; expected README.md under {root}", file=sys.stderr)
        return 1

    try:
        from huggingface_hub import HfApi, create_repo
    except ImportError:
        print("error: install huggingface_hub: pip install huggingface_hub", file=sys.stderr)
        return 1

    api = HfApi(token=args.token)
    create_repo(
        repo_id=args.repo_id,
        repo_type="model",
        private=args.private,
        exist_ok=True,
    )
    api.upload_folder(
        folder_path=str(root),
        repo_id=args.repo_id,
        repo_type="model",
        ignore_patterns=[
            ".git/**",
            ".git",
            "**/__pycache__/**",
            "**/*.pyc",
            "**/.DS_Store",
        ],
    )
    print(f"Uploaded: {root}")
    print(f"URL: https://huggingface.co/{args.repo_id}")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())