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

Update download_models.py

Browse files
Files changed (1) hide show
  1. download_models.py +62 -26
download_models.py CHANGED
@@ -1,36 +1,72 @@
1
- from huggingface_hub import hf_hub_download
2
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- def download_model(repo_id, filename):
5
- """Download and cache model using HF Hub"""
6
- print(f"Downloading {filename}...")
 
7
 
8
- # HF Hub automatically caches in ~/.cache/huggingface
9
- file_path = hf_hub_download(
10
- repo_id=repo_id,
11
- filename=filename,
12
- cache_dir=os.environ.get("HF_HOME", "/data/.cache/huggingface"), # Space persistent storage
13
  )
14
 
15
- # Create symlink in expected location
16
- local_path = filename
17
- os.makedirs(os.path.dirname(local_path), exist_ok=True)
 
 
 
 
 
 
 
 
18
 
19
- if not os.path.exists(local_path):
20
- os.symlink(file_path, local_path)
21
-
22
- print(f"✓ {filename} ready at {local_path}")
23
- return file_path
 
 
24
 
25
- def main():
26
- # # Download spatial checkpoint
27
- # download_model(
28
- # "Seed3D/MagicArticulate",
29
- # "skeleton_ckpt/checkpoint_trainonv2_spatial.pth"
30
  # )
31
 
32
- # Download hierarchical checkpoint
33
- download_model(
34
- "Seed3D/MagicArticulate",
35
- "skeleton_ckpt/checkpoint_trainonv2_hier.pth"
 
 
36
  )
 
 
 
 
 
 
 
 
 
1
  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()