bart / upload_workspace.py
sonithoiningombam's picture
Pushed file: upload_workspace.py
4744aaa verified
Raw
History Blame Contribute Delete
2.23 kB
import os
import time
from pathlib import Path
from huggingface_hub import upload_folder
# Setup your core configurations
FOLDER_PATH = "/teamspace/studios/this_studio"
REPO_ID = "sonithoiningombam/bart"
REPO_TYPE = "model"
# Correct patterns to completely ignore all dotfiles and hidden folders (.venv, .git, etc.)
IGNORE_PATTERNS = ["**/.*", "**/.*/**"]
print("πŸš€ Scanning workspace directories to chunk the upload safely...")
# Step 1: Discover top-level visible items to isolate the commits
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.")
# Step 2: Loop through items and push them to prevent commit explosion
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():
# If it's a standalone file in the root
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():
# If it's a folder, upload its contents safely to its relative path
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}")
# Step 3: Enforce a strict rest window to stay comfortably under 128 commits/hour
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!")