| |
| |
| """ |
| Script to upload robot trajectory dataset to Hugging Face Hub |
| """ |
|
|
| import os |
| import sys |
| from pathlib import Path |
| from huggingface_hub import HfApi, create_repo, upload_folder |
| from huggingface_hub.utils import HfHubHTTPError |
|
|
| def upload_dataset_to_hf( |
| local_folder_path=".", |
| repo_id=None, |
| token=None, |
| private=False, |
| repo_type="dataset" |
| ): |
| """ |
| Upload a local folder to Hugging Face as a dataset. |
| |
| Args: |
| local_folder_path: Path to the local folder to upload (default: current directory) |
| repo_id: HuggingFace repo ID (format: 'username/dataset-name') |
| token: HuggingFace API token |
| private: Whether to make the repo private (default: False) |
| repo_type: Type of repo (default: 'dataset') |
| """ |
| |
| |
| api = HfApi(token=token) |
| |
| |
| local_folder_path = Path(local_folder_path).absolute() |
| |
| print(f"π Preparing to upload from: {local_folder_path}") |
| |
| |
| total_files = sum(1 for _ in local_folder_path.rglob("*") if _.is_file()) |
| print(f"π Found {total_files} files to upload") |
| |
| try: |
| |
| print(f"π§ Creating repository: {repo_id}") |
| create_repo( |
| repo_id=repo_id, |
| token=token, |
| private=private, |
| repo_type=repo_type, |
| exist_ok=True |
| ) |
| print(f"β
Repository ready: {repo_id}") |
| |
| |
| print(f"π€ Starting upload...") |
| print(f" This may take a while depending on the size of your dataset...") |
| |
| |
| upload_folder( |
| folder_path=str(local_folder_path), |
| repo_id=repo_id, |
| repo_type=repo_type, |
| token=token, |
| ignore_patterns=["*.pyc", "__pycache__", ".git", ".DS_Store"], |
| commit_message="Upload robot trajectory dataset" |
| ) |
| |
| print(f"β
Successfully uploaded dataset to: https://huggingface.co/datasets/{repo_id}") |
| |
| except HfHubHTTPError as e: |
| print(f"β HTTP Error occurred: {e}") |
| sys.exit(1) |
| except Exception as e: |
| print(f"β An error occurred: {e}") |
| sys.exit(1) |
|
|
| def main(): |
| """Main function to run the upload script.""" |
| |
| |
| |
| |
| |
| REPO_ID = "ASethi04/robot-trajectories-dataset" |
| |
| |
| |
| HF_TOKEN = os.getenv("HF_TOKEN", None) |
| |
| |
| LOCAL_FOLDER = "." |
| |
| |
| PRIVATE = False |
| |
| |
| |
| |
| if not HF_TOKEN: |
| print("β Error: Hugging Face token not provided!") |
| print("Please either:") |
| print(" 1. Set the HF_TOKEN environment variable: export HF_TOKEN='your-token-here'") |
| print(" 2. Modify the HF_TOKEN variable in this script") |
| print("\nGet your token from: https://huggingface.co/settings/tokens") |
| sys.exit(1) |
| |
| if REPO_ID == "your-username/robot-trajectories-dataset": |
| print("β Error: Please update the REPO_ID with your Hugging Face username and desired dataset name!") |
| print("Format: 'username/dataset-name'") |
| sys.exit(1) |
| |
| |
| print("=" * 50) |
| print("π Upload Configuration:") |
| print(f" Repository: {REPO_ID}") |
| print(f" Local Path: {Path(LOCAL_FOLDER).absolute()}") |
| print(f" Private: {PRIVATE}") |
| print("=" * 50) |
| |
| response = input("\nβ οΈ Do you want to proceed with the upload? (yes/no): ").lower().strip() |
| |
| if response not in ['yes', 'y']: |
| print("β Upload cancelled.") |
| sys.exit(0) |
| |
| |
| upload_dataset_to_hf( |
| local_folder_path=LOCAL_FOLDER, |
| repo_id=REPO_ID, |
| token=HF_TOKEN, |
| private=PRIVATE |
| ) |
|
|
| if __name__ == "__main__": |
| main() |