ckc99u commited on
Commit
e07ea67
Β·
verified Β·
1 Parent(s): 36cbf88

Update download_models.py

Browse files
Files changed (1) hide show
  1. download_models.py +59 -53
download_models.py CHANGED
@@ -2,71 +2,77 @@ import os
2
  from huggingface_hub import hf_hub_download
3
  from pathlib import Path
4
 
5
- def download_with_retry(repo_id, filename, local_dir, max_retries=3):
6
- """Download file with retry logic"""
7
- for attempt in range(max_retries):
8
- try:
9
- print(f"Downloading {filename} (attempt {attempt + 1}/{max_retries})...")
10
- file_path = hf_hub_download(
11
- repo_id=repo_id,
12
- filename=filename,
13
- local_dir=local_dir,
14
- local_dir_use_symlinks=False # Important for Spaces
15
- )
16
- print(f"βœ“ Successfully downloaded: {filename}")
17
- return file_path
18
- except Exception as e:
19
- if attempt == max_retries - 1:
20
- print(f"βœ— Failed to download {filename}: {e}")
21
- raise
22
- print(f"Retry {attempt + 1} failed, trying again...")
23
- return None
24
 
25
- def main():
26
- print("=" * 50)
27
- print("Downloading MagicArticulate Model Checkpoints")
28
- print("=" * 50)
29
 
30
- # Create directories
31
- Path("skeleton_ckpt").mkdir(exist_ok=True)
32
- Path("third_partys/Michelangelo/checkpoints/aligned_shape_latents").mkdir(
33
- parents=True, exist_ok=True
34
-
35
- )
36
 
37
- # Download Michelangelo checkpoint (required dependency)
38
- print("\n[1/3] Downloading Michelangelo checkpoint...")
39
- try:
40
- download_with_retry(
41
- repo_id="Maikou/Michelangelo",
42
- filename="checkpoints/aligned_shape_latents/shapevae-256.ckpt",
43
- local_dir="third_partys/Michelangelo"
 
 
44
  )
45
- except Exception as e:
46
- print(f"Warning: Michelangelo download failed: {e}")
47
- print("This may affect some features.")
48
 
49
- # Download MagicArticulate spatial checkpoint
50
- # print("\n[2/3] Downloading MagicArticulate spatial checkpoint...")
51
- # download_with_retry(
52
- # repo_id="Seed3D/MagicArticulate",
53
- # filename="skeleton_ckpt/checkpoint_trainonv2_spatial.pth",
54
- # local_dir="."
55
-
 
 
 
 
 
 
 
 
 
56
 
57
- # )
 
 
 
 
 
 
 
 
 
 
58
 
59
- # Download MagicArticulate hierarchical checkpoint
60
- print("\n[3/3] Downloading MagicArticulate hierarchical checkpoint...")
61
- download_with_retry(
62
  repo_id="Seed3D/MagicArticulate",
63
  filename="skeleton_ckpt/checkpoint_trainonv2_hier.pth",
64
- local_dir="."
65
  )
 
 
 
 
 
 
 
66
 
67
  print("\n" + "=" * 50)
68
- print("βœ“ All downloads completed successfully!")
69
  print("=" * 50)
70
 
71
  if __name__ == "__main__":
72
- main()
 
2
  from huggingface_hub import hf_hub_download
3
  from pathlib import Path
4
 
5
+ # Define persistent storage paths
6
+ PERSISTENT_DIR = Path("/data")
7
+ CACHE_DIR = PERSISTENT_DIR / ".cache" / "magicarticulate"
8
+ CACHE_DIR.mkdir(parents=True, exist_ok=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ def download_and_link(repo_id, filename, target_local_path):
11
+ """Download to persistent storage and symlink to app directory"""
12
+ print(f"Processing {filename}...")
 
13
 
14
+ # Download to persistent cache
15
+ # We use hf_hub_download with a specific local_dir in persistent storage
16
+ # to ensure we control exactly where the file lives.
17
+ persistent_file_path = CACHE_DIR / filename
 
 
18
 
19
+ if persistent_file_path.exists():
20
+ print(f"βœ“ Found in cache: {persistent_file_path}")
21
+ else:
22
+ print(f"Downloading to persistent storage: {persistent_file_path}")
23
+ hf_hub_download(
24
+ repo_id=repo_id,
25
+ filename=filename,
26
+ local_dir=CACHE_DIR, # Download directly into /data
27
+ local_dir_use_symlinks=False
28
  )
 
 
 
29
 
30
+ # Create symlink in the application directory
31
+ target_path = Path(target_local_path)
32
+ target_path.parent.mkdir(parents=True, exist_ok=True)
33
+
34
+ if target_path.exists():
35
+ if target_path.is_symlink() and target_path.resolve() == persistent_file_path:
36
+ print(f"βœ“ Symlink already exists: {target_path}")
37
+ else:
38
+ # If it exists but isn't our symlink, remove it and link
39
+ if target_path.is_symlink() or target_path.is_file():
40
+ target_path.unlink()
41
+ target_path.symlink_to(persistent_file_path)
42
+ print(f"βœ“ Created symlink: {target_path} -> {persistent_file_path}")
43
+ else:
44
+ target_path.symlink_to(persistent_file_path)
45
+ print(f"βœ“ Created symlink: {target_path} -> {persistent_file_path}")
46
 
47
+ def main():
48
+ print("=" * 50)
49
+ print("Setting up models with Persistent Storage")
50
+ print("=" * 50)
51
+
52
+ # 1. Michelangelo Checkpoint
53
+ download_and_link(
54
+ repo_id="Maikou/Michelangelo",
55
+ filename="checkpoints/aligned_shape_latents/shapevae-256.ckpt",
56
+ target_local_path="third_partys/Michelangelo/checkpoints/aligned_shape_latents/shapevae-256.ckpt"
57
+ )
58
 
59
+ # 2. MagicArticulate Hierarchical Checkpoint
60
+ download_and_link(
 
61
  repo_id="Seed3D/MagicArticulate",
62
  filename="skeleton_ckpt/checkpoint_trainonv2_hier.pth",
63
+ target_local_path="skeleton_ckpt/checkpoint_trainonv2_hier.pth"
64
  )
65
+
66
+ # 3. MagicArticulate Spatial Checkpoint (Optional, uncomment if needed)
67
+ # download_and_link(
68
+ # repo_id="Seed3D/MagicArticulate",
69
+ # filename="skeleton_ckpt/checkpoint_trainonv2_spatial.pth",
70
+ # target_local_path="skeleton_ckpt/checkpoint_trainonv2_spatial.pth"
71
+ # )
72
 
73
  print("\n" + "=" * 50)
74
+ print("βœ“ Setup complete!")
75
  print("=" * 50)
76
 
77
  if __name__ == "__main__":
78
+ main()