File size: 3,357 Bytes
4e4f237 d1988f5 4e4f237 d1988f5 4e4f237 d1988f5 535fc66 4e4f237 d1988f5 6a39e70 535fc66 d1988f5 4e4f237 | 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | """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()
|