Download upload_hf.py from xLeverd/chess: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/datasets/xLeverd/chess/resolve/main/upload_hf.py
- Command line
-
hf download hf://datasets/xLeverd/chess/upload_hf.py
-
curl -L -o upload_hf.py https://huggingface.co/datasets/xLeverd/chess/resolve/main/upload_hf.py
1.86 kB
| #!/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() | |