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