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