LiamKhoaLe commited on
Commit
ad9ea09
·
1 Parent(s): 1db513a

Migrate snapshot folder files to parent

Browse files
Files changed (1) hide show
  1. download_model.py +24 -30
download_model.py CHANGED
@@ -9,37 +9,31 @@ MODEL_CACHE_DIR = "/app/model_cache"
9
  print("⏳ Downloading the SentenceTransformer model...")
10
  model_path = snapshot_download(repo_id=MODEL_REPO, cache_dir=MODEL_CACHE_DIR)
11
 
12
- # Find the correct snapshot directory
13
- # snapshots_dir = os.path.join(model_path, "snapshots")
14
- snapshots_dir = model_path
15
- print("Model path: ", snapshots_dir)
16
- if os.path.exists(snapshots_dir):
17
- snapshot_folders = os.listdir(snapshots_dir)
18
- if snapshot_folders:
19
- snapshot_dir = os.path.join(snapshots_dir, snapshot_folders[0]) # Get first snapshot folder (e.g., migrate config file)
20
- # Move all files and directories from the snapshot folder to /app/model_cache
21
- for item in os.listdir(snapshot_folders):
22
- source_path = os.path.join(snapshot_folders, item)
23
- dest_path = os.path.join(MODEL_CACHE_DIR, item)
24
- if os.path.exists(dest_path):
25
- shutil.rmtree(dest_path) if os.path.isdir(dest_path) else os.remove(dest_path)
26
- shutil.move(source_path, dest_path)
27
- print(f"📂 Moving model files from {snapshot_folders} to {MODEL_CACHE_DIR}...")
28
- # Move all model files (including subdirectories)
29
- for item in os.listdir(snapshot_dir):
30
- source_path = os.path.join(snapshot_dir, item)
31
- dest_path = os.path.join(MODEL_CACHE_DIR, item)
32
- if os.path.isdir(source_path):
33
- shutil.move(source_path, dest_path)
34
- else:
35
- shutil.move(source_path, dest_path)
36
-
37
- print(f"✅ Model extracted and flattened in {MODEL_CACHE_DIR}")
38
- else:
39
- print("❌ No snapshot folder found!")
40
- exit(1)
41
  else:
42
- print("❌ No snapshots directory found!")
43
  exit(1)
44
 
45
  # Verify structure
 
9
  print("⏳ Downloading the SentenceTransformer model...")
10
  model_path = snapshot_download(repo_id=MODEL_REPO, cache_dir=MODEL_CACHE_DIR)
11
 
12
+ # Find the correct model path and move files
13
+ print("Model path: ", model_path)
14
+
15
+ if os.path.exists(model_path):
16
+ # Ensure the destination directory is clean
17
+ if os.path.exists(MODEL_CACHE_DIR):
18
+ shutil.rmtree(MODEL_CACHE_DIR)
19
+ os.makedirs(MODEL_CACHE_DIR, exist_ok=True)
20
+
21
+ print(f"📂 Moving model files from {model_path} to {MODEL_CACHE_DIR}...")
22
+
23
+ # Move all files and directories from model_path to MODEL_CACHE_DIR
24
+ for item in os.listdir(model_path):
25
+ src_path = os.path.join(model_path, item)
26
+ dest_path = os.path.join(MODEL_CACHE_DIR, item)
27
+
28
+ # Move directories and files while preserving structure
29
+ if os.path.isdir(src_path):
30
+ shutil.move(src_path, dest_path)
31
+ else:
32
+ shutil.move(src_path, dest_path)
33
+
34
+ print(f"✅ Model extracted and flattened in {MODEL_CACHE_DIR}")
 
 
 
 
 
 
35
  else:
36
+ print("❌ Model download failed! Directory not found:", model_path)
37
  exit(1)
38
 
39
  # Verify structure