ummmar commited on
Commit
1dd14a3
·
verified ·
1 Parent(s): 845f96d

Create restore_workspace.py

Browse files
Files changed (1) hide show
  1. restore_workspace.py +23 -0
restore_workspace.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, shutil
2
+ from huggingface_hub import snapshot_download
3
+
4
+ HF_TOKEN = os.getenv("HF_TOKEN")
5
+ DATASET = os.getenv("HF_DATASET_REPO")
6
+ WORKSPACE = "/workspace/projects"
7
+
8
+ try:
9
+ print("⬇️ Restoring workspace from HF Dataset...")
10
+ snapshot_download(
11
+ repo_id=DATASET, repo_type="dataset",
12
+ local_dir="/tmp/ws_restore", token=HF_TOKEN,
13
+ ignore_patterns=[".git", "__pycache__"]
14
+ )
15
+ if os.path.exists(WORKSPACE):
16
+ shutil.rmtree(WORKSPACE)
17
+ shutil.copytree("/tmp/ws_restore", WORKSPACE)
18
+ print("✅ Workspace restored.")
19
+ except Exception as e:
20
+ print(f"⏭️ Fresh start (Dataset empty or missing): {e}")
21
+ finally:
22
+ shutil.rmtree("/tmp/ws_restore", ignore_errors=True)
23
+ os.makedirs(WORKSPACE, exist_ok=True)