Sraghvi's picture
Upload bimanual bone packing dataset with so101 folder structure
da5a206 verified
raw
history blame
3.05 kB
#!/usr/bin/env python3
"""
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()
# Create the repository if it doesn't exist
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}")
# Create temporary directory for extraction
with tempfile.TemporaryDirectory() as temp_dir:
print(f"Extracting {zip_path} to temporary directory...")
# Extract the zip file
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
# Find the extracted content
extracted_items = list(Path(temp_dir).iterdir())
if len(extracted_items) == 1 and extracted_items[0].is_dir():
# If there's a single directory, use its contents
source_dir = extracted_items[0]
else:
# Otherwise use the temp directory itself
source_dir = Path(temp_dir)
# Create the target folder structure
target_dir = source_dir / folder_name
target_dir.mkdir(exist_ok=True)
# Move all extracted content to the so101 folder
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}")
# Upload the dataset with pull request
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())