|
|
|
|
|
"""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() |
|
|
|