|
|
|
|
|
""" |
|
|
Script to upload the bimanual bone dataset to Hugging Face |
|
|
""" |
|
|
|
|
|
import os |
|
|
import zipfile |
|
|
import tempfile |
|
|
from pathlib import Path |
|
|
from huggingface_hub import HfApi, create_repo |
|
|
import argparse |
|
|
|
|
|
def extract_and_upload_dataset(zip_path, repo_id, folder_name="so101"): |
|
|
""" |
|
|
Extract the zip file and upload to Hugging Face dataset repository |
|
|
""" |
|
|
api = HfApi() |
|
|
|
|
|
|
|
|
try: |
|
|
create_repo(repo_id=repo_id, repo_type="dataset", exist_ok=True) |
|
|
print(f"Repository {repo_id} is ready") |
|
|
except Exception as e: |
|
|
print(f"Repository creation/verification: {e}") |
|
|
|
|
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir: |
|
|
print(f"Extracting {zip_path} to temporary directory...") |
|
|
|
|
|
|
|
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref: |
|
|
zip_ref.extractall(temp_dir) |
|
|
|
|
|
|
|
|
extracted_items = list(Path(temp_dir).iterdir()) |
|
|
if len(extracted_items) == 1 and extracted_items[0].is_dir(): |
|
|
|
|
|
source_dir = extracted_items[0] |
|
|
else: |
|
|
|
|
|
source_dir = Path(temp_dir) |
|
|
|
|
|
|
|
|
target_dir = source_dir / folder_name |
|
|
target_dir.mkdir(exist_ok=True) |
|
|
|
|
|
|
|
|
for item in source_dir.iterdir(): |
|
|
if item.name != folder_name: |
|
|
import shutil |
|
|
shutil.move(str(item), str(target_dir / item.name)) |
|
|
|
|
|
print(f"Uploading dataset to {repo_id}...") |
|
|
print(f"Source directory: {source_dir}") |
|
|
print(f"Target folder: {folder_name}") |
|
|
|
|
|
|
|
|
api.upload_folder( |
|
|
folder_path=str(source_dir), |
|
|
repo_id=repo_id, |
|
|
repo_type="dataset", |
|
|
commit_message="Upload bimanual bone packing dataset with so101 folder structure", |
|
|
create_pr=True |
|
|
) |
|
|
|
|
|
print("Dataset uploaded successfully!") |
|
|
|
|
|
def main(): |
|
|
parser = argparse.ArgumentParser(description="Upload bimanual bone dataset to Hugging Face") |
|
|
parser.add_argument("--zip-path", required=True, help="Path to the zip file") |
|
|
parser.add_argument("--repo-id", default="CHEWYSO/Chewy_Robotics_Bone_Bi-manual_Packing", |
|
|
help="Hugging Face repository ID") |
|
|
parser.add_argument("--folder-name", default="so101", |
|
|
help="Folder name to organize the dataset") |
|
|
|
|
|
args = parser.parse_args() |
|
|
|
|
|
if not os.path.exists(args.zip_path): |
|
|
print(f"Error: Zip file {args.zip_path} not found") |
|
|
return 1 |
|
|
|
|
|
extract_and_upload_dataset(args.zip_path, args.repo_id, args.folder_name) |
|
|
return 0 |
|
|
|
|
|
if __name__ == "__main__": |
|
|
exit(main()) |
|
|
|