Views
No views yet
diffuserspip install torch torchvision diffusers transformers acceleratediffusers from GitHub:pip install git+https://github.com/huggingface/diffusers1from diffusers import QwenImageEditPipeline
2import torch
3from PIL import Image
4
5# Load the pipeline
6pipeline = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509")
7pipeline.to(torch.bfloat16)
8pipeline.to("cuda")1# Load trained LoRA weights for in-scene editing
2pipeline.load_lora_weights("flymy-ai/qwen-image-edit-2509-inscene-lora", weight_name="pytorch_lora_weights.safetensors")1# Load input image
2image = Image.open("./assets/qie2_input.jpg").convert("RGB")
3
4# Define in-scene editing prompt
5prompt = "Make a shot in the same scene of the left hand securing the edge of the cutting board while the right hand tilts it, causing the chopped tomatoes to slide off into the pan, camera angle shifts slightly to the left to center more on the pan."
6
7# Generate edited image with enhanced scene understanding
8inputs = {
9 "image": image,
10 "prompt": prompt,
11 "generator": torch.manual_seed(0),
12 "true_cfg_scale": 4.0,
13 "negative_prompt": " ",
14 "num_inference_steps": 50,
15}
16
17with torch.inference_mode():
18 output = pipeline(**inputs)
19 output_image = output.images[0]
20 output_image.save("edited_image.png")
