| import os |
| import time |
| from pathlib import Path |
| from huggingface_hub import upload_folder |
|
|
| |
| FOLDER_PATH = "/teamspace/studios/this_studio" |
| REPO_ID = "sonithoiningombam/bart" |
| REPO_TYPE = "model" |
|
|
| |
| IGNORE_PATTERNS = ["**/.*", "**/.*/**"] |
|
|
| print("π Scanning workspace directories to chunk the upload safely...") |
|
|
| |
| root_path = Path(FOLDER_PATH) |
| items_to_upload = [ |
| item for item in root_path.iterdir() |
| if not item.name.startswith('.') |
| ] |
|
|
| print(f"π¦ Found {len(items_to_upload)} root items to process sequentially.") |
|
|
| |
| for index, item in enumerate(items_to_upload, start=1): |
| print(f"\nπ [{index}/{len(items_to_upload)}] Uploading: {item.name}...") |
| |
| try: |
| if item.is_file(): |
| |
| upload_folder( |
| folder_path=str(root_path), |
| repo_id=REPO_ID, |
| repo_type=REPO_TYPE, |
| allow_patterns=[item.name], |
| commit_message=f"Pushed file: {item.name}" |
| ) |
| elif item.is_dir(): |
| |
| upload_folder( |
| folder_path=str(item), |
| repo_id=REPO_ID, |
| repo_type=REPO_TYPE, |
| path_in_repo=item.name, |
| ignore_patterns=IGNORE_PATTERNS, |
| commit_message=f"Pushed directory segment: {item.name}" |
| ) |
| print(f"β
Finished uploading: {item.name}") |
| |
| |
| print("π Cooling down for 30 seconds to respect Hugging Face API rate limits...") |
| time.sleep(30) |
|
|
| except Exception as e: |
| print(f"β οΈ Failed to upload {item.name} due to: {e}") |
| print("π‘ The script will continue to the next item. You can re-run later to retry failed objects.") |
|
|
| print("\nπ Workspace segment loops finished successfully!") |
|
|