import os os.environ['HF_HUB_DISABLE_SYMLINKS_WARNING'] = '1' from diffusers import QwenImageEditPipeline import torch from PIL import Image import glob def find_image(): script_dir = os.path.dirname(os.path.abspath(__file__)) extensions = ['*.png', '*.jpg', '*.jpeg', '*.webp', '*.bmp'] for ext in extensions: files = glob.glob(os.path.join(script_dir, ext)) if files: return files[0] return None input_image_path = find_image() if not input_image_path: print("Error: No image found in script directory") exit(1) print(f"Loading image: {os.path.basename(input_image_path)}") image = Image.open(input_image_path).convert("RGB") max_size = 768 if max(image.size) > max_size: image.thumbnail((max_size, max_size), Image.Resampling.LANCZOS) print("Loading model...") device = "cuda" if torch.cuda.is_available() else "cpu" dtype = torch.float16 if torch.cuda.is_available() else torch.float32 pipeline = QwenImageEditPipeline.from_pretrained( "Qwen/Qwen-Image-Edit", torch_dtype=dtype ) if torch.cuda.is_available(): pipeline.enable_attention_slicing() pipeline.enable_vae_slicing() pipeline.to(device) print("Loading LoRA...") pipeline.load_lora_weights( "Jonny001/Qwen-Image-Edit-Remove-Clothes", weight_name="qwen-edit-remove-clothes.safetensors" ) print("Generating...") inputs = { "image": image, "prompt": "remove all the clothes of the figure in the picture", "generator": torch.manual_seed(12345), "true_cfg_scale": 4.0, "negative_prompt": " ", "num_inference_steps": 50, } with torch.inference_mode(): output = pipeline(**inputs) output_image = output.images[0] output_path = "result.png" output_image.save(output_path) print(f"Saved: {output_path}")