| |
| """Push the staging tree to the HuggingFace dataset repo. |
| |
| Two upload paths: |
| * SMALL files (README, previews/, assets/, scripts/, cameras.json, smplx.npz, |
| capture.json, preview.jpg) -> `upload_folder`, one atomic commit. |
| * BIG files (data/<PxCy>/videos/*.mp4, ~2 GiB per capture) -> `upload_large_folder`, |
| which is chunked, multi-worker and RESUMABLE: it keeps per-file state under |
| <staging>/.cache/huggingface, so re-running after a network drop skips what is done. |
| |
| Usage: |
| python hf_upload.py --staging .../staging --capture P1C1 # meta + that capture |
| python hf_upload.py --staging .../staging --meta-only # README/previews/scripts |
| python hf_upload.py --staging .../staging --capture P1C1 --videos-only |
| """ |
| from __future__ import annotations |
|
|
| import argparse |
| import json |
| import sys |
| from pathlib import Path |
|
|
| from huggingface_hub import HfApi |
|
|
| REPO_ID = "initialneil/DREAMS-AVATAR" |
|
|
| META_PATTERNS = [ |
| "README.md", "LICENSE", |
| "previews/*.jsonl", "previews/*.jpg", "assets/**/*.jpg", |
| "scripts/*.py", "scripts/*.sh", |
| ] |
| CAPTURE_SMALL = ["data/{cap}/cameras.json", "data/{cap}/smplx.npz", |
| "data/{cap}/capture.json", "data/{cap}/preview.jpg"] |
| CAPTURE_BIG = ["data/{cap}/videos/*.mp4"] |
|
|
|
|
| def ensure_repo(api: HfApi, repo_id: str, private: bool) -> str: |
| url = api.create_repo(repo_id=repo_id, repo_type="dataset", private=private, |
| exist_ok=True) |
| info = api.repo_info(repo_id=repo_id, repo_type="dataset") |
| print(f"[repo] {url} private={info.private}", flush=True) |
| return str(url) |
|
|
|
|
| def main() -> int: |
| ap = argparse.ArgumentParser(description=__doc__, |
| formatter_class=argparse.RawDescriptionHelpFormatter) |
| ap.add_argument("--staging", type=Path, required=True) |
| ap.add_argument("--repo-id", default=REPO_ID) |
| ap.add_argument("--capture", default=None) |
| ap.add_argument("--meta-only", action="store_true") |
| ap.add_argument("--videos-only", action="store_true") |
| ap.add_argument("--private", action="store_true", help="create as private (default PUBLIC)") |
| ap.add_argument("--prune-previews", action="store_true", |
| help="delete repo previews/showcase jpgs that are no longer in staging " |
| "(needed when frame labels change). Never touches data/ or scripts/.") |
| ap.add_argument("--workers", type=int, default=4) |
| a = ap.parse_args() |
|
|
| api = HfApi() |
| who = api.whoami()["name"] |
| print(f"[hf] logged in as {who}", flush=True) |
| ensure_repo(api, a.repo_id, a.private) |
|
|
| if not a.videos_only: |
| pats = list(META_PATTERNS) |
| if a.capture: |
| pats += [p.format(cap=a.capture) for p in CAPTURE_SMALL] |
| msg = (f"Add {a.capture} metadata + SMPL-X + previews" if a.capture |
| else "Update dataset card / previews / scripts") |
| |
| |
| dels = ["previews/*.jpg", "assets/showcase/*.jpg"] if a.prune_previews else None |
| print(f"[upload] small files: {pats}", flush=True) |
| if dels: |
| print(f"[upload] pruning stale: {dels}", flush=True) |
| ci = api.upload_folder(repo_id=a.repo_id, repo_type="dataset", |
| folder_path=str(a.staging), allow_patterns=pats, |
| delete_patterns=dels, commit_message=msg) |
| print(f"[upload] commit {getattr(ci, 'oid', ci)}", flush=True) |
|
|
| if a.capture and not a.meta_only: |
| pats = [p.format(cap=a.capture) for p in CAPTURE_BIG] |
| print(f"[upload] LARGE (resumable): {pats}", flush=True) |
| api.upload_large_folder(repo_id=a.repo_id, repo_type="dataset", |
| folder_path=str(a.staging), allow_patterns=pats, |
| num_workers=a.workers, print_report=True, |
| print_report_every=30) |
| print("[upload] large folder done", flush=True) |
|
|
| files = api.list_repo_files(repo_id=a.repo_id, repo_type="dataset") |
| print(json.dumps({"repo": f"https://huggingface.co/datasets/{a.repo_id}", |
| "n_files": len(files)})) |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|