import spaces import torch from PIL import Image from diffusers import QwenImageEditPlusPipeline from diffusers.utils import load_image import gradio as gr pipe = QwenImageEditPlusPipeline.from_pretrained( "Qwen/Qwen-Image-Edit-2509", torch_dtype=torch.bfloat16 ).to("cuda") @spaces.GPU() def extract_clothes(img1): pipe.load_lora_weights("JamesDigitalOcean/Qwen_Image_Edit_Extract_Clothing", weight_names = "qwen_image_edit_remove_body.safetensors", adapter_names = "removebody") pil_image = Image.fromarray(img1, 'RGB') # image_1 = load_image(img1) # print(type(image_1)) image = pipe( image=[pil_image], prompt="removebody remove the person from this image, but leave the outfit. the clothes should remain after deleting the person's body, skin, and hair. leave the clothes in front of a white background", num_inference_steps=50 ).images[0] pipe.delete_adapters("removebody") return image @spaces.GPU() def tryon_clothes(img2, img3): pipe.load_lora_weights("JamesDigitalOcean/Qwen_Image_Edit_Try_On_Clothes", weight_names = "qwen_image_edit_tryon.safetensors", adapter_names = "tryonclothes") pil_image2 = Image.fromarray(img2, 'RGB') pil_image3 = Image.fromarray(img3, 'RGB') image = pipe( image=[pil_image2, pil_image3], prompt="tryon_clothes dress the clothing onto the person", num_inference_steps=50 ).images[0] pipe.delete_adapters("tryonclothes") return image with gr.Blocks() as demo: gr.Markdown("