feylur commited on
Commit
0e6a4e7
Β·
verified Β·
1 Parent(s): 853b9df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -26
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
- # Download and cache models
31
- repo_path = snapshot_download(
32
- repo_id="zhengchong/CatVTON",
33
- cache_dir="/tmp/models" # For CPU basic tier
34
- )
35
-
36
- print("βœ… Models downloaded! Initializing pipeline...")
37
-
38
- # Initialize pipeline for CPU
39
- pipeline = CatVTONPipeline(
40
- base_ckpt="booksforcharlie/stable-diffusion-inpainting",
41
- attn_ckpt=repo_path,
42
- attn_ckpt_version="mix",
43
- weight_dtype=torch.float32, # CPU uses fp32
44
- use_tf32=False, # CPU doesn't support TF32
45
- device='cpu'
46
- )
47
-
48
- automasker = AutoMasker(
49
- densepose_ckpt=os.path.join(repo_path, "DensePose"),
50
- schp_ckpt=os.path.join(repo_path, "SCHP"),
51
- device='cpu'
52
- )
53
-
54
- print("βœ… Models loaded successfully!")
 
 
 
 
 
 
 
 
 
 
 
 
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"""