Download code/scripts/upload_hf.py from eduzrh/LNPBench: direct link, hf CLI and curl.
- Browser
- Download file 3.36 kB
-
https://huggingface.co/datasets/eduzrh/LNPBench/resolve/main/code/scripts/upload_hf.py
- Command line
-
hf download hf://datasets/eduzrh/LNPBench/code/scripts/upload_hf.py
-
curl -L -o upload_hf.py https://huggingface.co/datasets/eduzrh/LNPBench/resolve/main/code/scripts/upload_hf.py
3.36 kB
| """Upload code, caches, results and figures to a Hugging Face dataset repo. | |
| The dataset card is maintained as a plain markdown file (`hf_card.md`) at the | |
| repository root and copied verbatim, so it can be edited without touching this | |
| script. | |
| Usage:: | |
| HF_TOKEN=hf_... python scripts/upload_hf.py [--skip-code] | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import os | |
| import shutil | |
| import tempfile | |
| from pathlib import Path | |
| from huggingface_hub import HfApi, create_repo | |
| DEFAULT_REPO = "eduzrh/LNPBench" | |
| def main() -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--repo", default=DEFAULT_REPO) | |
| ap.add_argument("--root", default=str(Path(__file__).resolve().parents[1])) | |
| ap.add_argument("--token", default=os.environ.get("HF_TOKEN")) | |
| ap.add_argument("--private", action="store_true") | |
| ap.add_argument("--skip-code", action="store_true") | |
| args = ap.parse_args() | |
| assert args.token, "set HF_TOKEN" | |
| root = Path(args.root) | |
| card_path = root / "hf_card.md" | |
| assert card_path.exists(), f"missing {card_path}" | |
| card = card_path.read_text() | |
| api = HfApi(token=args.token) | |
| create_repo(args.repo, repo_type="dataset", token=args.token, exist_ok=True, private=args.private) | |
| print("repo:", args.repo) | |
| with tempfile.TemporaryDirectory() as tmp: | |
| stage = Path(tmp) | |
| (stage / "README.md").write_text(card) | |
| if not args.skip_code: | |
| shutil.copytree( | |
| root / "src", stage / "code" / "src", | |
| ignore=shutil.ignore_patterns("__pycache__", "*.pyc"), | |
| ) | |
| shutil.copytree(root / "scripts", stage / "code" / "scripts", | |
| ignore=shutil.ignore_patterns("__pycache__", "*.pyc")) | |
| for name in ("README.md", "requirements.txt", "pyproject.toml", | |
| "PROGRESS.md", "METHODS.md", "TODO.md", "hf_card.md"): | |
| if (root / name).exists(): | |
| shutil.copy2(root / name, stage / "code" / name) | |
| for name in ("PROGRESS.md", "METHODS.md", "TODO.md"): | |
| if (root / name).exists(): | |
| shutil.copy2(root / name, stage / name) | |
| for sub in ("results", "figures", "manuscript"): | |
| src = root / sub | |
| if src.exists(): | |
| shutil.copytree(src, stage / sub, dirs_exist_ok=True, | |
| ignore=shutil.ignore_patterns("__pycache__", "*.pyc")) | |
| cache = root / "cache" | |
| keep = [ | |
| "il_fp.npy", "il_desc.npy", "il_cpp.npy", "il_vocab.json", | |
| "il_desc_names.json", "il_tokens.npz", "token_vocab.json", | |
| "sample_features.npz", "tasks.pkl", "md_labels.npz", | |
| "samples.parquet", "unified_phys.npz", "il_fp_prot.npy", | |
| ] | |
| (stage / "cache").mkdir(exist_ok=True) | |
| for name in keep: | |
| if (cache / name).exists(): | |
| shutil.copy2(cache / name, stage / "cache" / name) | |
| for f in cache.glob("frag_*.npz"): | |
| shutil.copy2(f, stage / "cache" / f.name) | |
| api.upload_folder( | |
| folder_path=stage, repo_id=args.repo, repo_type="dataset", | |
| commit_message="LNPBench: code, caches, results and figures", | |
| ) | |
| print(f"done -> https://huggingface.co/datasets/{args.repo}") | |
| if __name__ == "__main__": | |
| main() | |