Zuii commited on
Commit
f618454
Β·
verified Β·
1 Parent(s): 4f1e299

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
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
- 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
 
 
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