| """Upload one audited strict640x480-v2 task atomically to the public Hub repo.""" |
| from __future__ import annotations |
|
|
| import argparse |
| import json |
| import os |
| from io import BytesIO |
| from pathlib import Path |
|
|
| from huggingface_hub import CommitOperationAdd, HfApi |
| from huggingface_hub._commit_api import _fetch_upload_modes |
|
|
|
|
| def main() -> None: |
| parser = argparse.ArgumentParser() |
| parser.add_argument("--task", required=True) |
| parser.add_argument("--source", required=True) |
| args = parser.parse_args() |
| source = Path(args.source) |
| audit = source / "strict_audit.json" |
| report = json.loads(audit.read_text(encoding="utf-8")) |
| if report.get("status") != "PASS_STRICT640X480_V2" or report.get("episodes") != 100: |
| raise ValueError(f"refusing upload of non-formal task audit: {report}") |
| token = os.environ.get("HF_TOKEN") |
| if not token: |
| raise RuntimeError("HF_TOKEN is required for formal-data upload") |
| |
| |
| |
| |
| |
| files = sorted( |
| p for p in source.rglob("*") |
| if p.is_file() and ".cache" not in p.parts and p.name != "hf_upload_receipt.json" |
| ) |
| prefix = f"strict640x480-v2/data/{args.task}" |
| api = HfApi(token=token) |
| headers = api._build_hf_headers(token=token) |
| repo_id = "B111ue/RoboFactory-5Task-RGBD-Decentralized" |
| remote_files = set(api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=token)) |
| for file in files: |
| remote_path = f"{prefix}/{file.relative_to(source).as_posix()}" |
| if remote_path in remote_files: |
| print(f"HF_FILE_ALREADY_PRESENT {remote_path}") |
| continue |
| operation = CommitOperationAdd(path_in_repo=remote_path, path_or_fileobj=str(file)) |
| |
| |
| |
| |
| _fetch_upload_modes( |
| additions=[operation], |
| repo_type="dataset", |
| repo_id=repo_id, |
| headers=headers, |
| revision="main", |
| endpoint=api.endpoint, |
| ) |
| if operation._upload_mode == "lfs": |
| api.preupload_lfs_files( |
| repo_id=repo_id, |
| additions=[operation], |
| token=token, |
| repo_type="dataset", |
| revision="main", |
| num_threads=1, |
| free_memory=False, |
| ) |
| api.create_commit( |
| repo_id=repo_id, |
| repo_type="dataset", |
| operations=[operation], |
| commit_message=f"strict640x480-v2: stage {args.task}/{file.name}", |
| token=token, |
| num_threads=1, |
| ) |
| print(f"HF_FILE_COMMITTED {remote_path}") |
| receipt = {"task": args.task, "audit": report, "status": "COMPLETE_STRICT640X480_V2"} |
| result = api.create_commit( |
| repo_id=repo_id, |
| repo_type="dataset", |
| operations=[CommitOperationAdd( |
| path_in_repo=f"{prefix}/hf_upload_receipt.json", |
| path_or_fileobj=BytesIO(json.dumps(receipt, indent=2).encode("utf-8")), |
| )], |
| commit_message=f"strict640x480-v2: publish audited {args.task} (100 demos)", |
| token=token, |
| num_threads=1, |
| ) |
| (source / "hf_upload_receipt.json").write_text(json.dumps({**receipt, "revision": str(result)}, indent=2), encoding="utf-8") |
| print(f"HF_UPLOAD_VERIFIED {args.task} {result}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|