File size: 1,136 Bytes
845f96d 4740fdd 845f96d 92ba885 4740fdd 2d12dd3 223a9a6 4740fdd 223a9a6 92ba885 4740fdd 223a9a6 4740fdd 845f96d 223a9a6 92ba885 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 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) |