ummmar commited on
Commit
2d12dd3
·
verified ·
1 Parent(s): 2e8869e

Update sync_workspace.py

Browse files
Files changed (1) hide show
  1. sync_workspace.py +7 -11
sync_workspace.py CHANGED
@@ -3,34 +3,30 @@ from huggingface_hub import HfApi
3
 
4
  TOKEN = os.getenv("MY_HF_TOKEN")
5
  DATASET = os.getenv("HF_DATASET_REPO")
6
- WORKSPACE = "/workspace/projects"
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
- # Pass token directly to HfApi instead of using global login()
13
  api = HfApi(token=TOKEN)
14
 
15
  try:
16
  api.create_repo(repo_id=DATASET, repo_type="dataset", private=True, exist_ok=True)
17
- print(f"✅ Dataset {DATASET} verified/created.")
18
  except Exception as e:
19
  print(f"❌ Dataset access failed: {e}")
20
- print(" Ensure MY_HF_TOKEN has WRITE permission and dataset name is correct.")
21
  exit(0)
22
 
23
- IGNORES = [
24
- ".git", "node_modules", ".venv", "__pycache__", "dist", "build",
25
- "*.log", "*.tmp", "*.pyc", ".next", ".cache", "vendor", "target"
26
- ]
27
-
28
  while True:
29
  try:
30
  api.upload_folder(
31
- folder_path=WORKSPACE, repo_id=DATASET, repo_type="dataset",
32
- commit_message="Auto-sync", ignore_patterns=IGNORES
 
 
 
33
  )
 
34
  except Exception as e:
35
  print(f"Sync failed: {e}")
36
  time.sleep(300)
 
3
 
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)