aiqcamp commited on
Commit
c80bdec
β€’
1 Parent(s): 56ef9fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -8
app.py CHANGED
@@ -39,6 +39,29 @@ def pil_to_binary_mask(pil_image, threshold=0):
39
  output_mask = Image.fromarray(mask)
40
  return output_mask
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  base_path = 'yisol/IDM-VTON'
43
  example_path = os.path.join(os.path.dirname(__file__), 'example')
44
 
@@ -151,8 +174,8 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
151
  model_parse, _ = parsing_model(human_img.resize((384,512)))
152
  mask, mask_gray = get_mask_location('hd', category, model_parse, keypoints)
153
  mask = mask.resize((768,1024))
154
- except NotImplementedError:
155
- status_message = f"μΉ΄ν…Œκ³ λ¦¬ {category}에 λŒ€ν•œ μžλ™ 마슀크 생성이 κ΅¬ν˜„λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. κΈ°λ³Έ 마슀크λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€."
156
  mask = Image.new('L', (768, 1024), 255)
157
  else:
158
  if dict['layers'] and dict['layers'][0]:
@@ -252,7 +275,6 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
252
  else:
253
  return images[0], mask_gray, status_message
254
 
255
-
256
  garm_list = os.listdir(os.path.join(example_path,"cloth"))
257
  garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]
258
 
@@ -267,8 +289,6 @@ for ex_human in human_list_path:
267
  ex_dict['composite'] = None
268
  human_ex_list.append(ex_dict)
269
 
270
- ##default human
271
-
272
  image_blocks = gr.Blocks(theme="Nymbo/Nymbo_Theme").queue(max_size=12)
273
  with image_blocks as demo:
274
  with gr.Column():
@@ -315,11 +335,9 @@ with image_blocks as demo:
315
  with gr.Column():
316
  status_message = gr.Textbox(label="μƒνƒœ", interactive=False)
317
 
318
-
319
-
320
  try_button.click(fn=start_tryon,
321
  inputs=[imgs, garm_img, prompt, is_checked, is_checked_crop, denoise_steps, seed, category],
322
  outputs=[image_out, masked_img, status_message],
323
  api_name='tryon')
324
 
325
- image_blocks.launch(auth=("gini","pick"))
 
39
  output_mask = Image.fromarray(mask)
40
  return output_mask
41
 
42
+ # utils_mask.py νŒŒμΌμ— μžˆλŠ” get_mask_location ν•¨μˆ˜λ₯Ό μˆ˜μ •ν•©λ‹ˆλ‹€.
43
+ def get_mask_location(mode, category, parsing, keypoints):
44
+ parsing = np.array(parsing)
45
+ mask = np.zeros_like(parsing)
46
+
47
+ if category == "μƒμ˜":
48
+ # μƒμ˜μ— ν•΄λ‹Ήν•˜λŠ” λΆ€λΆ„ λ§ˆμŠ€ν‚Ή (예: μƒμ˜, λ“œλ ˆμŠ€ 상단뢀)
49
+ mask[np.isin(parsing, [5, 6, 7])] = 255
50
+ elif category == "ν•˜μ˜":
51
+ # ν•˜μ˜μ— ν•΄λ‹Ήν•˜λŠ” λΆ€λΆ„ λ§ˆμŠ€ν‚Ή (예: 바지, 치마)
52
+ mask[np.isin(parsing, [9, 12, 13, 14, 15, 16, 17, 18, 19])] = 255
53
+ elif category == "λ“œλ ˆμŠ€":
54
+ # λ“œλ ˆμŠ€μ— ν•΄λ‹Ήν•˜λŠ” λΆ€λΆ„ λ§ˆμŠ€ν‚Ή (μƒμ˜μ™€ ν•˜μ˜ λͺ¨λ‘ 포함)
55
+ mask[np.isin(parsing, [5, 6, 7, 9, 12, 13, 14, 15, 16, 17, 18, 19])] = 255
56
+ else:
57
+ raise ValueError(f"Unknown category: {category}")
58
+
59
+ # ν‚€ν¬μΈνŠΈλ₯Ό μ‚¬μš©ν•˜μ—¬ 마슀크 μ˜μ—­μ„ 더 μ •ν™•ν•˜κ²Œ μ‘°μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
60
+ # 예λ₯Ό λ“€μ–΄, μƒμ˜μ˜ 경우 어깨와 ν—ˆλ¦¬ μ‚¬μ΄μ˜ μ˜μ—­μœΌλ‘œ μ œν•œν•  수 μžˆμŠ΅λ‹ˆλ‹€.
61
+
62
+ mask_gray = Image.fromarray(mask)
63
+ return mask_gray, mask_gray
64
+
65
  base_path = 'yisol/IDM-VTON'
66
  example_path = os.path.join(os.path.dirname(__file__), 'example')
67
 
 
174
  model_parse, _ = parsing_model(human_img.resize((384,512)))
175
  mask, mask_gray = get_mask_location('hd', category, model_parse, keypoints)
176
  mask = mask.resize((768,1024))
177
+ except Exception as e:
178
+ status_message = f"μžλ™ 마슀크 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}. κΈ°λ³Έ 마슀크λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€."
179
  mask = Image.new('L', (768, 1024), 255)
180
  else:
181
  if dict['layers'] and dict['layers'][0]:
 
275
  else:
276
  return images[0], mask_gray, status_message
277
 
 
278
  garm_list = os.listdir(os.path.join(example_path,"cloth"))
279
  garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]
280
 
 
289
  ex_dict['composite'] = None
290
  human_ex_list.append(ex_dict)
291
 
 
 
292
  image_blocks = gr.Blocks(theme="Nymbo/Nymbo_Theme").queue(max_size=12)
293
  with image_blocks as demo:
294
  with gr.Column():
 
335
  with gr.Column():
336
  status_message = gr.Textbox(label="μƒνƒœ", interactive=False)
337
 
 
 
338
  try_button.click(fn=start_tryon,
339
  inputs=[imgs, garm_img, prompt, is_checked, is_checked_crop, denoise_steps, seed, category],
340
  outputs=[image_out, masked_img, status_message],
341
  api_name='tryon')
342
 
343
+ image_blocks.launch(auth=("gini","pick"))