ummmar commited on
Commit
223a9a6
·
verified ·
1 Parent(s): c4e0cac

Update sync_workspace.py

Browse files
Files changed (1) hide show
  1. sync_workspace.py +18 -14
sync_workspace.py CHANGED
@@ -4,29 +4,33 @@ from huggingface_hub import HfApi
4
  TOKEN = os.getenv("MY_HF_TOKEN")
5
  DATASET = os.getenv("HF_DATASET_REPO")
6
  CONFIG_DIR = "/workspace/config"
 
7
 
8
  if not TOKEN or not DATASET:
9
- print("⏭️ Sync skipped: MY_HF_TOKEN or HF_DATASET_REPO not set.")
10
  exit(0)
11
 
12
  api = HfApi(token=TOKEN)
13
-
14
  try:
15
  api.create_repo(repo_id=DATASET, repo_type="dataset", private=True, exist_ok=True)
16
  except Exception as e:
17
- print(f"❌ Dataset access failed: {e}")
18
  exit(0)
19
 
20
  while True:
21
- try:
22
- api.upload_folder(
23
- folder_path=CONFIG_DIR,
24
- repo_id=DATASET,
25
- repo_type="dataset",
26
- commit_message="Config sync",
27
- ignore_patterns=["*.tmp", "*.log"]
28
- )
29
- print(f"✅ Config synced at {time.strftime('%H:%M:%S')}")
30
- except Exception as e:
31
- print(f"Sync failed: {e}")
 
 
 
 
32
  time.sleep(300)
 
4
  TOKEN = os.getenv("MY_HF_TOKEN")
5
  DATASET = os.getenv("HF_DATASET_REPO")
6
  CONFIG_DIR = "/workspace/config"
7
+ DATA_DIR = "/workspace/data"
8
 
9
  if not TOKEN or not DATASET:
10
+ print("⏭️ Sync skipped.")
11
  exit(0)
12
 
13
  api = HfApi(token=TOKEN)
 
14
  try:
15
  api.create_repo(repo_id=DATASET, repo_type="dataset", private=True, exist_ok=True)
16
  except Exception as e:
17
+ print(f"❌ Dataset failed: {e}")
18
  exit(0)
19
 
20
  while True:
21
+ for label, path in [("config", CONFIG_DIR), ("sessions", DATA_DIR)]:
22
+ if not os.path.exists(path):
23
+ continue
24
+ try:
25
+ api.upload_folder(
26
+ folder_path=path,
27
+ repo_id=DATASET,
28
+ repo_type="dataset",
29
+ path_in_repo=label, # ← stores under /config/ and /sessions/ in dataset
30
+ commit_message=f"{label} sync",
31
+ ignore_patterns=["*.tmp", "*.log", "*.lock"]
32
+ )
33
+ print(f"✅ {label} synced at {time.strftime('%H:%M:%S')}")
34
+ except Exception as e:
35
+ print(f"{label} sync failed: {e}")
36
  time.sleep(300)