Datasets:
scripts: downloader supports --group models|piano|eval
Browse files122345678789101112101113141516177 unmodified lines2526272829303132334 unmodified lines383940414243444546474849505152533754555639575859606162454647486364655051666753686970715772737475616276777879806781828384857186878889#!/usr/bin/env python3"""Download the BrickMore-48 archives from Hugging Face and verify every SHA-256."""Download the BrickForma dataset archives from Hugging Face and verify every SHA-256.
Examples-------- pip install huggingface_hub python scripts/download_from_hf.py --output brickmore80k python scripts/download_from_hf.py --output brickmore80k --shard A --extract-metadata python scripts/download_from_hf.py --group models --output brickforma80k python scripts/download_from_hf.py --group models --shard A --output brickforma80k --extract-metadata python scripts/download_from_hf.py --group piano --output brickforma80k python scripts/download_from_hf.py --group eval --output brickforma80k python scripts/download_from_hf.py --group all --output brickforma80k
The repository is private, so log in first (`huggingface-cli login`) or pass --token,or set the HF_TOKEN environment variable.The repository is private, so log in first (`huggingface-cli login`) or pass --token, orset the HF_TOKEN environment variable."""import argparseimport hashlib7 unmodified lines
REPO_ID = "VergilLLLL/BrickForma-DataSet"MANIFEST_IN_REPO = "checksums/SHA256_MANIFEST.json"GROUPS = {"models": ("data/AI_A/", "data/AI_B/"), "piano": ("data/piano_B_supported_1905/",), "eval": ("evaluation/",)}
def sha256(path):4 unmodified lines return digest.hexdigest()
def selected(entry, group, shard): path = entry["path"] if group == "all": return True if not path.startswith(GROUPS[group]): return False if group == "models" and shard != "all": return path.startswith(f"data/AI_{shard}/") return True
def main(): parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("--output", type=Path, default=Path("brickmore80k")) parser.add_argument("--output", type=Path, default=Path("brickforma80k")) parser.add_argument("--group", choices=("models", "piano", "eval", "all"), default="models") parser.add_argument("--shard", choices=("all", "A", "B"), default="all") parser.add_argument("--extract-metadata", action="store_true", help="unzip the two metadata archives") parser.add_argument("--extract-metadata", action="store_true", help="unzip the metadata archives") parser.add_argument("--token", default=os.environ.get("HF_TOKEN")) parser.add_argument("--revision", default=None) args = parser.parse_args() args.output.mkdir(parents=True, exist_ok=True)
manifest_path = Path( hf_hub_download(REPO_ID, MANIFEST_IN_REPO, repo_type="dataset", token=args.token, revision=args.revision, local_dir=args.output) ) manifest_path = Path(hf_hub_download(REPO_ID, MANIFEST_IN_REPO, repo_type="dataset", token=args.token, revision=args.revision, local_dir=str(args.output))) manifest = json.loads(manifest_path.read_text(encoding="utf-8")) wanted = [entry for entry in manifest["files"] if args.shard == "all" or entry["path"].split("/")[1] == f"AI_{args.shard}"] wanted = [entry for entry in manifest["files"] if selected(entry, args.group, args.shard)] total = sum(entry["bytes"] for entry in wanted) print(f"{len(wanted)} archives, {total / 1e9:.2f} GB, from {REPO_ID}") print(f"{len(wanted)} archives, {total / 1e9:.2f} GB, group={args.group}, from {REPO_ID}")
for index, entry in enumerate(wanted, 1): target = Path(hf_hub_download(REPO_ID, entry["path"], repo_type="dataset", token=args.token, revision=args.revision, local_dir=args.output)) revision=args.revision, local_dir=str(args.output))) size = target.stat().st_size if size != entry["bytes"]: sys.exit(f"size mismatch for {entry['path']}: {size} != {entry['bytes']}") digest = sha256(target) if digest != entry["sha256"]: if sha256(target) != entry["sha256"]: sys.exit(f"sha256 mismatch for {entry['path']}") print(f"[{index}/{len(wanted)}] verified {entry['path']} ({size / 1e6:.0f} MB)")
if args.extract_metadata: for archive in ("data/AI_A/metadata.zip", "data/AI_B/B_metadata.zip"): for archive in ("data/AI_A/metadata.zip", "data/AI_B/B_metadata.zip", "data/piano_B_supported_1905/piano_B_supported_training_metadata.zip"): path = args.output / archive if not path.exists(): continue destination = args.output / "metadata" / archive.split("/")[1] destination = args.output / "metadata" / Path(archive).stem destination.mkdir(parents=True, exist_ok=True) with zipfile.ZipFile(path) as bundle: bundle.extractall(destination)scripts/download_from_hf.py+34-19