Zuii commited on
Commit
0d53021
Β·
verified Β·
1 Parent(s): fd0a2c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -61,6 +61,7 @@ def tryon(person_img, cloth_img, seed, random_seed):
61
  person_img = cv2.resize(person_img, (256, 256))
62
  cloth_img = cv2.resize(cloth_img, (256, 256))
63
 
 
64
  # πŸ”₯ Blend garment onto person (simple overlay β€” still has blue tint)
65
  output_img = person_img.copy()
66
  h, w, _ = person_img.shape
@@ -70,11 +71,20 @@ def tryon(person_img, cloth_img, seed, random_seed):
70
  x_offset = (w - g_w) // 2
71
  y_offset = int(h * 0.35)
72
 
 
 
 
 
73
  # πŸ› οΈ Add garment onto person (no transparency support β€” raw overlay)
74
  output_img[y_offset:y_offset + g_h, x_offset:x_offset + g_w] = cloth_img
75
 
76
  return output_img, seed, "βœ… Success (Blue tint + Garment added)"
77
 
 
 
 
 
 
78
 
79
  # πŸ”§ Paths for examples
80
  example_path = os.path.join(os.path.dirname(__file__), "assets")
 
61
  person_img = cv2.resize(person_img, (256, 256))
62
  cloth_img = cv2.resize(cloth_img, (256, 256))
63
 
64
+ try:
65
  # πŸ”₯ Blend garment onto person (simple overlay β€” still has blue tint)
66
  output_img = person_img.copy()
67
  h, w, _ = person_img.shape
 
71
  x_offset = (w - g_w) // 2
72
  y_offset = int(h * 0.35)
73
 
74
+ # βœ… Ensure garment fits inside the person image
75
+ if y_offset + g_h > h or x_offset + g_w > w:
76
+ raise ValueError("❗ Garment image is too large for the person image!")
77
+
78
  # πŸ› οΈ Add garment onto person (no transparency support β€” raw overlay)
79
  output_img[y_offset:y_offset + g_h, x_offset:x_offset + g_w] = cloth_img
80
 
81
  return output_img, seed, "βœ… Success (Blue tint + Garment added)"
82
 
83
+ except Exception as e:
84
+ print(f"❌ Error in tryon function: {e}")
85
+ return person_img, seed, f"❌ Error: {e}"
86
+
87
+
88
 
89
  # πŸ”§ Paths for examples
90
  example_path = os.path.join(os.path.dirname(__file__), "assets")