Update download_models.py
Browse files- 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 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 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
|
| 26 |
-
|
| 27 |
-
print("
|
| 28 |
-
print("=" * 50)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
)
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
)
|
| 45 |
-
except Exception as e:
|
| 46 |
-
print(f"Warning: Michelangelo download failed: {e}")
|
| 47 |
-
print("This may affect some features.")
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
|
| 61 |
-
download_with_retry(
|
| 62 |
repo_id="Seed3D/MagicArticulate",
|
| 63 |
filename="skeleton_ckpt/checkpoint_trainonv2_hier.pth",
|
| 64 |
-
|
| 65 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
print("\n" + "=" * 50)
|
| 68 |
-
print("β
|
| 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()
|