Update app.py
Browse files
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")
|