cloudcode / sync_workspace.py
ummmar's picture
Update sync_workspace.py
2d12dd3 verified
Raw History Blame
865 Bytes
import os, time
from huggingface_hub import HfApi
TOKEN = os.getenv("MY_HF_TOKEN")
DATASET = os.getenv("HF_DATASET_REPO")
CONFIG_DIR = "/workspace/config"
if not TOKEN or not DATASET:
print("⏭️ Sync skipped: MY_HF_TOKEN or HF_DATASET_REPO not set.")
exit(0)
api = HfApi(token=TOKEN)
try:
api.create_repo(repo_id=DATASET, repo_type="dataset", private=True, exist_ok=True)
except Exception as e:
print(f"❌ Dataset access failed: {e}")
exit(0)
while True:
try:
api.upload_folder(
folder_path=CONFIG_DIR,
repo_id=DATASET,
repo_type="dataset",
commit_message="Config sync",
ignore_patterns=["*.tmp", "*.log"]
)
print(f"✅ Config synced at {time.strftime('%H:%M:%S')}")
except Exception as e:
print(f"Sync failed: {e}")
time.sleep(300)