| import os | |
| from huggingface_hub import HfApi | |
| # ββββββββββββββββ | |
| # CONFIGURATION | |
| # ββββββββββββββββ | |
| HF_TOKEN = os.getenv("HF_TOKEN") # ensure: export HF_TOKEN="hf_xxxβ¦" | |
| REPO_ID = "agreeupon/wrkspace-backup-ttl" # YOUR_HF_USERNAME/YOUR_REPO_NAME | |
| VOL_PATH = "/workspace" # your RunPod mount | |
| REPO_TYPE = "dataset" # or "model" | |
| # ββββββββββββββββ | |
| # 1) Initialize API (with token) & create repo if needed | |
| # ββββββββββββββββ | |
| api = HfApi(token=HF_TOKEN) | |
| try: | |
| api.create_repo( | |
| repo_id = REPO_ID, | |
| repo_type= REPO_TYPE, | |
| private = False, # public = free unlimited | |
| exist_ok = True # skip error if it already exists | |
| ) | |
| print(f"β Repo ready: {REPO_ID}") | |
| except TypeError: | |
| # If your version doesn't support exist_ok, just ignore conflicts: | |
| pass | |
| # ββββββββββββββββ | |
| # 2) Remove stray .index.json pointers (to avoid LFS errors) | |
| # ββββββββββββββββ | |
| for root, _, files in os.walk(VOL_PATH): | |
| for fname in files: | |
| if fname.endswith(".index.json"): | |
| os.remove(os.path.join(root, fname)) | |
| print("ποΈ Removed any .index.json files") | |
| # ββββββββββββββββ | |
| # 3) Parallel large-folder upload | |
| # ββββββββββββββββ | |
| api.upload_large_folder( | |
| repo_id = REPO_ID, | |
| repo_type = REPO_TYPE, | |
| folder_path = VOL_PATH, | |
| ignore_patterns = [ | |
| ".git", "__pycache__", "*.pyc", "*.tmp", "*.DS_Store" | |
| ] | |
| ) | |
| print("π Large-folder upload complete!") | |