File size: 1,864 Bytes
88d26e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49e1668
 
 
 
 
 
 
 
 
 
 
88d26e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Upload the generated shards to the Hugging Face dataset xLeverd/chess."""

from __future__ import annotations

import argparse
import os
from pathlib import Path

from huggingface_hub import HfApi


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("--repo", default="xLeverd/chess")
    parser.add_argument("--data-dir", default="data")
    parser.add_argument("--token", default=os.environ.get("HF_TOKEN"))
    parser.add_argument("--private", action="store_true")
    args = parser.parse_args()

    if not args.token:
        raise SystemExit("Set HF_TOKEN or pass --token")

    api = HfApi(token=args.token)
    api.create_repo(args.repo, repo_type="dataset", private=args.private, exist_ok=True)

    data_dir = Path(args.data_dir)
    if not data_dir.is_dir():
        raise SystemExit(f"no such directory: {data_dir}")

    print(f"uploading {data_dir} -> {args.repo}/data")
    api.upload_folder(
        repo_id=args.repo,
        repo_type="dataset",
        folder_path=str(data_dir),
        path_in_repo="data",
        commit_message="Add Stockfish distillation shards",
    )

    val_dir = Path("val")
    if val_dir.is_dir():
        print(f"uploading {val_dir} -> {args.repo}/val")
        api.upload_folder(
            repo_id=args.repo,
            repo_type="dataset",
            folder_path=str(val_dir),
            path_in_repo="val",
            commit_message="Add validation shard",
        )

    readme = Path("README.md")
    if readme.is_file():
        api.upload_file(
            repo_id=args.repo,
            repo_type="dataset",
            path_or_fileobj=str(readme),
            path_in_repo="README.md",
            commit_message="Add dataset card",
        )

    print(f"https://huggingface.co/datasets/{args.repo}")


if __name__ == "__main__":
    main()