import os, shutil from huggingface_hub import snapshot_download TOKEN = os.getenv("MY_HF_TOKEN") DATASET = os.getenv("HF_DATASET_REPO") CONFIG_DIR = "/workspace/config" DATA_DIR = "/workspace/data" PROJECTS_DIR = "/workspace/projects" for d in [CONFIG_DIR, DATA_DIR, PROJECTS_DIR]: os.makedirs(d, exist_ok=True) if not TOKEN or not DATASET: print("⏭️ Restore skipped.") exit(0) try: print("⬇️ Restoring config & sessions...") snapshot_download( repo_id=DATASET, repo_type="dataset", local_dir="/tmp/ws_restore", token=TOKEN ) # Restore config/ and sessions/ subdirs from dataset for subdir, target in [("config", CONFIG_DIR), ("sessions", DATA_DIR)]: src = os.path.join("/tmp/ws_restore", subdir) if os.path.exists(src): if os.path.exists(target): shutil.rmtree(target) shutil.copytree(src, target) print(f"✅ {subdir} restored.") except Exception as e: print(f"⏭️ Fresh start: {e}") finally: shutil.rmtree("/tmp/ws_restore", ignore_errors=True)