Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,36 +22,48 @@ def load_models():
|
|
| 22 |
"""Load models once at startup"""
|
| 23 |
global pipeline, automasker
|
| 24 |
|
| 25 |
-
if pipeline is not None:
|
| 26 |
return
|
| 27 |
|
| 28 |
print("π Downloading/Loading CatVTON models (first time may take 5-10 mins)...")
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
def generate_tryon(person_img, cloth_img, progress=gr.Progress()):
|
| 57 |
"""Generate virtual try-on"""
|
|
|
|
| 22 |
"""Load models once at startup"""
|
| 23 |
global pipeline, automasker
|
| 24 |
|
| 25 |
+
if pipeline is not None and automasker is not None:
|
| 26 |
return
|
| 27 |
|
| 28 |
print("π Downloading/Loading CatVTON models (first time may take 5-10 mins)...")
|
| 29 |
|
| 30 |
+
try:
|
| 31 |
+
# Download and cache models
|
| 32 |
+
repo_path = snapshot_download(
|
| 33 |
+
repo_id="zhengchong/CatVTON",
|
| 34 |
+
cache_dir="/tmp/models"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
print(f"β
Models downloaded to: {repo_path}")
|
| 38 |
+
print(f"DensePose path exists: {os.path.exists(os.path.join(repo_path, 'DensePose'))}")
|
| 39 |
+
print(f"SCHP path exists: {os.path.exists(os.path.join(repo_path, 'SCHP'))}")
|
| 40 |
+
|
| 41 |
+
print("Initializing pipeline...")
|
| 42 |
+
pipeline = CatVTONPipeline(
|
| 43 |
+
base_ckpt="booksforcharlie/stable-diffusion-inpainting",
|
| 44 |
+
attn_ckpt=repo_path,
|
| 45 |
+
attn_ckpt_version="mix",
|
| 46 |
+
weight_dtype=torch.float32,
|
| 47 |
+
use_tf32=False,
|
| 48 |
+
device='cpu'
|
| 49 |
+
)
|
| 50 |
+
print("β
Pipeline loaded!")
|
| 51 |
+
|
| 52 |
+
print("Initializing automasker...")
|
| 53 |
+
automasker = AutoMasker(
|
| 54 |
+
densepose_ckpt=os.path.join(repo_path, "DensePose"),
|
| 55 |
+
schp_ckpt=os.path.join(repo_path, "SCHP"),
|
| 56 |
+
device='cpu'
|
| 57 |
+
)
|
| 58 |
+
print("β
Automasker loaded!")
|
| 59 |
+
|
| 60 |
+
print(f"Final check - Pipeline: {pipeline is not None}, Automasker: {automasker is not None}")
|
| 61 |
+
|
| 62 |
+
except Exception as e:
|
| 63 |
+
print(f"β Error loading models: {e}")
|
| 64 |
+
import traceback
|
| 65 |
+
traceback.print_exc()
|
| 66 |
+
raise
|
| 67 |
|
| 68 |
def generate_tryon(person_img, cloth_img, progress=gr.Progress()):
|
| 69 |
"""Generate virtual try-on"""
|