cloudcode / sync_workspace.py
ummmar's picture
Update sync_workspace.py
223a9a6 verified
Raw History Blame Contribute Delete
1.14 kB
import os, time
from huggingface_hub import HfApi
TOKEN = os.getenv("MY_HF_TOKEN")
DATASET = os.getenv("HF_DATASET_REPO")
CONFIG_DIR = "/workspace/config"
DATA_DIR = "/workspace/data"
if not TOKEN or not DATASET:
print("⏭️ Sync skipped.")
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 failed: {e}")
exit(0)
while True:
for label, path in [("config", CONFIG_DIR), ("sessions", DATA_DIR)]:
if not os.path.exists(path):
continue
try:
api.upload_folder(
folder_path=path,
repo_id=DATASET,
repo_type="dataset",
path_in_repo=label, # ← stores under /config/ and /sessions/ in dataset
commit_message=f"{label} sync",
ignore_patterns=["*.tmp", "*.log", "*.lock"]
)
print(f"✅ {label} synced at {time.strftime('%H:%M:%S')}")
except Exception as e:
print(f"{label} sync failed: {e}")
time.sleep(300)