Spaces:
Saad0KH
/
Running on Zero

Saad0KH commited on
Commit
e271adc
ยท
verified ยท
1 Parent(s): f0876aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -282,7 +282,7 @@ def tryon():
282
  'mask_image': mask_base64
283
  })
284
 
285
-
286
  def combine_images_with_masks(tops_image, bottoms_image, mask, is_checked_crop, crop_size):
287
  try:
288
  # Logique de combinaison des images de haut et de bas
@@ -329,10 +329,15 @@ def start_tryon_full_body(tops_image, bottoms_image, model_parse_tops, model_par
329
  human_img = human_img_orig.resize((768, 1024))
330
 
331
  if is_checked:
332
- keypoints = openpose_model(human_img.resize((384, 512)))
333
- model_parse, _ = parsing_model(human_img.resize((384, 512)))
334
- mask, mask_gray = get_mask_location('hd', "full_body", model_parse, keypoints)
335
- mask = mask.resize((768, 1024))
 
 
 
 
 
336
  else:
337
  mask = pil_to_binary_mask(model_parse_tops.convert("RGB").resize((768, 1024)))
338
  mask_gray = (1 - transforms.ToTensor()(mask)) * tensor_transfrom(human_img)
@@ -425,6 +430,9 @@ def start_tryon_full_body(tops_image, bottoms_image, model_parse_tops, model_par
425
 
426
 
427
 
 
 
 
428
  @app.route('/tryon-full', methods=['POST'])
429
  def tryon_full():
430
  try:
 
282
  'mask_image': mask_base64
283
  })
284
 
285
+
286
  def combine_images_with_masks(tops_image, bottoms_image, mask, is_checked_crop, crop_size):
287
  try:
288
  # Logique de combinaison des images de haut et de bas
 
329
  human_img = human_img_orig.resize((768, 1024))
330
 
331
  if is_checked:
332
+ try:
333
+ keypoints = openpose_model(human_img.resize((384, 512)))
334
+ model_parse, _ = parsing_model(human_img.resize((384, 512)))
335
+ if 'bodies' not in keypoints or 'subset' not in keypoints['bodies'] or len(keypoints['bodies']['subset']) == 0:
336
+ raise ValueError("No pose keypoints found in the model output.")
337
+ mask, mask_gray = get_mask_location('hd', "full_body", model_parse, keypoints)
338
+ mask = mask.resize((768, 1024))
339
+ except Exception as e:
340
+ raise ValueError(f"Error processing keypoints or mask: {e}")
341
  else:
342
  mask = pil_to_binary_mask(model_parse_tops.convert("RGB").resize((768, 1024)))
343
  mask_gray = (1 - transforms.ToTensor()(mask)) * tensor_transfrom(human_img)
 
430
 
431
 
432
 
433
+
434
+
435
+
436
  @app.route('/tryon-full', methods=['POST'])
437
  def tryon_full():
438
  try: