File size: 2,456 Bytes
56b1ab6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Upload the prepared viewer files to the Hugging Face Hub."""
from __future__ import annotations

import argparse
import json
from pathlib import Path
from typing import Dict

from datasets import Dataset

ROOT = Path(__file__).resolve().parents[1]
DATA_DIR = ROOT / "data"
CONFIGS = {
    "clue": DATA_DIR / "clue" / "train.jsonl",
    "mep": DATA_DIR / "mep" / "train.jsonl",
}


def read_stats() -> Dict[str, Dict[str, int]]:
    stats_path = DATA_DIR / "stats.json"
    if not stats_path.exists():
        return {}
    with stats_path.open("r", encoding="utf-8") as handle:
        return json.load(handle)


def push_config(config_name: str, file_path: Path, repo_id: str, args: argparse.Namespace) -> None:
    if not file_path.exists():
        raise FileNotFoundError(f"Missing file for config '{config_name}': {file_path}")
    print(f"Loading {config_name} from {file_path.relative_to(ROOT)} ...")
    dataset = Dataset.from_json(str(file_path))
    dataset.push_to_hub(
        repo_id=repo_id,
        config_name=config_name,
        split=args.split,
        private=args.private,
        token=args.token,
        branch=args.branch,
        max_shard_size=args.max_shard_size,
    )
    print(f"✓ Uploaded {config_name}/{args.split} to {repo_id}")


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--repo", required=True, help="Target dataset repo id, e.g. user/cuebench")
    parser.add_argument("--split", default="train", help="Split name to register on the Hub (default: train)")
    parser.add_argument("--branch", default=None, help="Optional branch to push to (defaults to repo default)")
    parser.add_argument("--token", default=None, help="HuggingFace token; omit if already logged in via CLI")
    parser.add_argument("--private", action="store_true", help="Mark the uploaded dataset as private")
    parser.add_argument("--max-shard-size", default="500MB", help="Shard threshold passed to push_to_hub")
    args = parser.parse_args()

    stats = read_stats()
    for config_name, path in CONFIGS.items():
        push_config(config_name, path, args.repo, args)
        if config_name in stats:
            summary = stats[config_name]
            print(
                f"  ↳ stats: {summary.get('num_examples', '?')} examples, "
                f"{summary.get('num_bytes', '?')} bytes"
            )


if __name__ == "__main__":
    main()