mimo-1.0 / setup_hf_spaces.py
minhho's picture
Clean deployment: All fixes without binary files
6f2c7f0
#!/usr/bin/env python3
"""
Setup script for HuggingFace Spaces deployment
Downloads required models and assets for MIMO
"""
import os
import sys
from pathlib import Path
from huggingface_hub import snapshot_download, hf_hub_download
def setup_hf_spaces():
"""Setup models and assets for HF Spaces"""
print("πŸš€ Setting up MIMO for HuggingFace Spaces...")
# Create directories
os.makedirs("./models", exist_ok=True)
os.makedirs("./assets", exist_ok=True)
try:
# 1. Download MIMO models
print("πŸ“₯ Downloading MIMO models...")
snapshot_download(
repo_id="menyifang/MIMO",
cache_dir="./models",
allow_patterns=["*.pth", "*.json", "*.md"]
)
print("βœ… MIMO models downloaded")
# 2. Download base models
print("πŸ“₯ Downloading Stable Diffusion v1.5...")
snapshot_download(
repo_id="runwayml/stable-diffusion-v1-5",
cache_dir="./models/stable-diffusion-v1-5"
)
print("βœ… Stable Diffusion downloaded")
print("πŸ“₯ Downloading VAE...")
snapshot_download(
repo_id="stabilityai/sd-vae-ft-mse",
cache_dir="./models/sd-vae-ft-mse"
)
print("βœ… VAE downloaded")
print("πŸ“₯ Downloading image encoder...")
snapshot_download(
repo_id="lambdalabs/sd-image-variations-diffusers",
cache_dir="./models/image_encoder",
allow_patterns=["image_encoder/**"]
)
print("βœ… Image encoder downloaded")
# 3. Download human segmenter
print("πŸ“₯ Downloading human segmenter...")
hf_hub_download(
repo_id="menyifang/MIMO",
filename="matting_human.pb",
cache_dir="./assets",
local_dir="./assets"
)
print("βœ… Human segmenter downloaded")
# 4. Create minimal assets
print("πŸ“ Creating asset directories...")
os.makedirs("./assets/test_image", exist_ok=True)
os.makedirs("./assets/masks", exist_ok=True)
print("πŸŽ‰ HuggingFace Spaces setup complete!")
return True
except Exception as e:
print(f"❌ Setup failed: {e}")
return False
if __name__ == "__main__":
setup_hf_spaces()