Download sync_workspace.py from ummmar/cloudcode: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/ummmar/cloudcode/resolve/bc3fa4907ddd7bd90a6540bf689e079b85b4237f/sync_workspace.py
- Command line
-
hf download hf://spaces/ummmar/cloudcode@bc3fa4907ddd7bd90a6540bf689e079b85b4237f/sync_workspace.py
-
curl -L -o sync_workspace.py https://huggingface.co/spaces/ummmar/cloudcode/resolve/bc3fa4907ddd7bd90a6540bf689e079b85b4237f/sync_workspace.py
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) |