Spaces:
Runtime error
Runtime error
yisol commited on
Commit ·
ab2e314
1
Parent(s): c123434
add auto crop
Browse files121 unmodified lines1221231241251261271281 unmodified line13013113213313413513613779 unmodified lines21721821922022122222317 unmodified lines2412422432442452462477 unmodified lines25525625725825926026113 unmodified lines275276277278279280281121 unmodified linespipe.unet_encoder = UNet_Encoder@spaces.GPUdef start_tryon(dict,garm_img,garment_des,is_checked,denoise_steps,seed):device = "cuda"openpose_model.preprocessor.body_estimation.model.to(device)1 unmodified linepipe.unet_encoder.to(device)garm_img= garm_img.convert("RGB").resize((768,1024))human_img = dict["background"].resize((768,1024)).convert("RGB")if is_checked:keypoints = openpose_model(human_img.resize((384,512)))model_parse, _ = parsing_model(human_img.resize((384,512)))79 unmodified linesip_adapter_image = garm_img.resize((768,1024)),guidance_scale=2.0,)[0]return images[0], mask_graygarm_list = os.listdir(os.path.join(example_path,"cloth"))garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]17 unmodified lineswith gr.Column():imgs = gr.ImageEditor(sources='upload', type="pil", label='Human. Mask with pen or use auto-masking', interactive=True)with gr.Row():is_checked = gr.Checkbox(label="Yes", info="Use auto-generated mask (Takes 5 more seconds)",value=True)example = gr.Examples(inputs=imgs,examples_per_page=10,7 unmodified linesprompt = gr.Textbox(placeholder="Description of garment ex) Short Sleeve Round Neck T-shirts", show_label=False, elem_id="prompt")example = gr.Examples(inputs=garm_img,examples_per_page=10,examples=garm_list_path)with gr.Column():# image_out = gr.Image(label="Output", elem_id="output-img", height=400)13 unmodified linesseed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)try_button.click(fn=start_tryon, inputs=[imgs, garm_img, prompt, is_checked, denoise_steps, seed], outputs=[image_out,masked_img], api_name='tryon')121 unmodified lines1221231241251261271281 unmodified line13013113213313413513613713813914014114214314414514614714814915015115279 unmodified lines23223323423523623723823924024124224324424517 unmodified lines2632642652662672682692702712727 unmodified lines28028128228328428528613 unmodified lines300301302303304305306121 unmodified linespipe.unet_encoder = UNet_Encoder@spaces.GPUdef start_tryon(dict,garm_img,garment_des,is_checked,is_checked_crop,denoise_steps,seed):device = "cuda"openpose_model.preprocessor.body_estimation.model.to(device)1 unmodified linepipe.unet_encoder.to(device)garm_img= garm_img.convert("RGB").resize((768,1024))human_img_orig = dict["background"].resize((768,1024)).convert("RGB")if is_checked_crop:width, height = human_img_orig.sizetarget_width = int(min(width, height * (3 / 4)))target_height = int(min(height, width * (4 / 3)))left = (width - target_width) / 2top = (height - target_height) / 2right = (width + target_width) / 2bottom = (height + target_height) / 2cropped_img = human_img_orig.crop((left, top, right, bottom))crop_size = cropped_img.sizehuman_img = cropped_img.resize((768,1024))else:human_img = human_img_orig.resize((768,1024))if is_checked:keypoints = openpose_model(human_img.resize((384,512)))model_parse, _ = parsing_model(human_img.resize((384,512)))79 unmodified linesip_adapter_image = garm_img.resize((768,1024)),guidance_scale=2.0,)[0]if is_checked_crop:out_img = images[0].resize(crop_size)human_img_orig.paste(out_img, (int(left), int(top)))return human_img_orig, mask_grayelse:return images[0], mask_gray# return images[0], mask_graygarm_list = os.listdir(os.path.join(example_path,"cloth"))garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]17 unmodified lineswith gr.Column():imgs = gr.ImageEditor(sources='upload', type="pil", label='Human. Mask with pen or use auto-masking', interactive=True)with gr.Row():is_checked = gr.Checkbox(label="Yes", info="Use auto-generated mask (Takes 5 seconds)",value=True)with gr.Row():is_checked_crop = gr.Checkbox(label="Yes", info="Use auto-crop & resizing",value=False)example = gr.Examples(inputs=imgs,examples_per_page=10,7 unmodified linesprompt = gr.Textbox(placeholder="Description of garment ex) Short Sleeve Round Neck T-shirts", show_label=False, elem_id="prompt")example = gr.Examples(inputs=garm_img,examples_per_page=8,examples=garm_list_path)with gr.Column():# image_out = gr.Image(label="Output", elem_id="output-img", height=400)13 unmodified linesseed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)try_button.click(fn=start_tryon, inputs=[imgs, garm_img, prompt, is_checked,is_checked_crop, denoise_steps, seed], outputs=[image_out,masked_img], api_name='tryon')
app.py+31-6