| |
| """ |
| 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...") |
|
|
| |
| os.makedirs("./models", exist_ok=True) |
| os.makedirs("./assets", exist_ok=True) |
|
|
| try: |
| |
| print("π₯ Downloading MIMO models...") |
| snapshot_download( |
| repo_id="menyifang/MIMO", |
| cache_dir="./models", |
| allow_patterns=["*.pth", "*.json", "*.md"] |
| ) |
| print("β
MIMO models downloaded") |
|
|
| |
| 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") |
|
|
| |
| 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") |
|
|
| |
| 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() |