File size: 1,860 Bytes
8510f62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Upload the exported `hf_dist/` CCRB benchmark directory to Hugging Face Hub."""

from __future__ import annotations

import argparse
import os
import sys
from pathlib import Path


def main(argv: list[str] | None = None) -> int:
    parser = argparse.ArgumentParser(description="Push CCRB hf_dist/ to Hugging Face Hub.")
    parser.add_argument("--folder", type=Path, default=Path("hf_dist"))
    parser.add_argument("--repo-id", type=str, default="continuum-oss/ccrb")
    parser.add_argument("--private", action="store_true", help="Create repo as private if new.")
    parser.add_argument(
        "--commit-message",
        type=str,
        default="Upload CCRB v0.2-dev cybersecurity retrieval benchmark",
    )
    args = parser.parse_args(argv)

    if not args.folder.exists():
        print(
            f"Export folder {args.folder} not found. Run `python scripts/export_huggingface.py` first.",
            file=sys.stderr,
        )
        return 1

    try:
        from huggingface_hub import HfApi  # type: ignore[import-not-found]
    except ImportError:
        print(
            "Missing `huggingface_hub`. Install it with:\n  pip install huggingface_hub",
            file=sys.stderr,
        )
        return 1

    token = os.environ.get("HF_TOKEN") or None
    api = HfApi(token=token)
    api.create_repo(
        repo_id=args.repo_id,
        repo_type="dataset",
        private=args.private,
        exist_ok=True,
    )
    print(f"[hf] Uploading {args.folder} -> https://huggingface.co/datasets/{args.repo_id}")
    api.upload_folder(
        folder_path=str(args.folder),
        repo_id=args.repo_id,
        repo_type="dataset",
        commit_message=args.commit_message,
    )
    print(f"[done] Published to https://huggingface.co/datasets/{args.repo_id}")
    return 0


if __name__ == "__main__":
    sys.exit(main())