wrkspace-backup-ttl / upload_to_hf.py
agreeupon's picture
Add files using upload-large-folder tool
5f9a50b verified
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!")