Update app.py
Browse files
app.py
CHANGED
@@ -86,25 +86,25 @@ def tryon(person_img, garment_img, seed, randomize_seed):
|
|
86 |
retry_delay = 3 # Faster retries now!
|
87 |
|
88 |
try:
|
89 |
-
|
90 |
|
91 |
# π οΈ Ensure both images are resized to 256x256
|
92 |
-
|
93 |
-
|
94 |
|
95 |
# π― Handle transparency if the garment has an alpha channel
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
|
101 |
# π§ Optional: Center the garment on the torso area
|
102 |
-
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
|
109 |
# β
Now the rest of your code continues here (retry loop, API call, etc.)
|
110 |
|
|
|
86 |
retry_delay = 3 # Faster retries now!
|
87 |
|
88 |
try:
|
89 |
+
session = requests.Session()
|
90 |
|
91 |
# π οΈ Ensure both images are resized to 256x256
|
92 |
+
person_img = cv2.resize(person_img, (256, 256))
|
93 |
+
garment_img = cv2.resize(garment_img, (256, 256))
|
94 |
|
95 |
# π― Handle transparency if the garment has an alpha channel
|
96 |
+
if garment_img.shape[-1] == 4:
|
97 |
+
alpha = garment_img[:, :, 3] / 255.0
|
98 |
+
for c in range(0, 3):
|
99 |
+
person_img[:, :, c] = (1 - alpha) * person_img[:, :, c] + alpha * garment_img[:, :, c]
|
100 |
|
101 |
# π§ Optional: Center the garment on the torso area
|
102 |
+
h, w, _ = person_img.shape
|
103 |
+
g_h, g_w, _ = garment_img.shape
|
104 |
|
105 |
+
x_offset = (w - g_w) // 2
|
106 |
+
y_offset = int(h * 0.35) # Adjust this value for higher/lower garment placement
|
107 |
+
person_img[y_offset:y_offset + g_h, x_offset:x_offset + g_w] = garment_img
|
108 |
|
109 |
# β
Now the rest of your code continues here (retry loop, API call, etc.)
|
110 |
|