### Start Qwen-Image Gradio Demo Server Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Starts the Gradio demo server for Qwen-Image, enabling a web interface with multi-GPU processing, queue management, and prompt optimization. Requires setting the DASHSCOPE_API_KEY. ```bash cd src DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxxxxxx python examples/demo.py ``` -------------------------------- ### Run Prompt Enhancement Script from Command Line Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Executes the prompt enhancement example script from the command line. Requires setting the DASHSCOPE_API_KEY environment variable. ```bash cd src DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxxxxxxxxx python examples/generate_w_prompt_enhance.py ``` -------------------------------- ### Server Configuration and MultiGPUManager Source: https://context7.com/qwenlm/qwen-image/llms.txt Example server configuration showing how environment variables are read and printed. The MultiGPUManager handles task distribution, queue management, progress tracking, and shutdown. ```python import os import torch from multiprocessing import Process, Queue, Event # Configuration from environment NUM_GPUS_TO_USE = int(os.environ.get("NUM_GPUS_TO_USE", torch.cuda.device_count())) TASK_QUEUE_SIZE = int(os.environ.get("TASK_QUEUE_SIZE", 100)) TASK_TIMEOUT = int(os.environ.get("TASK_TIMEOUT", 300)) print(f"Config: Using {NUM_GPUS_TO_USE} GPUs, queue size {TASK_QUEUE_SIZE}, timeout {TASK_TIMEOUT} seconds") # The MultiGPUManager handles: # - Task distribution across GPUs # - Queue management for high concurrency # - Progress tracking # - Graceful shutdown with cleanup # API available at: # - GET /api/status - Returns queue and worker status # - POST /api/generate - Submit generation task # Output: JSON with task_queue_size, result_queue_size, pending_tasks, active_workers ``` -------------------------------- ### Full Example: Command-Line Generation with Prompt Enhancement Source: https://context7.com/qwenlm/qwen-image/llms.txt A complete Python script demonstrating command-line image generation with automatic prompt enhancement using the Qwen-Image pipeline. Includes aspect ratio definitions and prompt rewriting. ```python from diffusers import DiffusionPipeline from tools.prompt_utils import rewrite import torch # Initialize the pipeline pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=torch.bfloat16) pipe = pipe.to("cuda") # Available aspect ratios with optimal dimensions aspect_ratios = { "1:1": (1328, 1328), "16:9": (1664, 928), "9:16": (928, 1664), "4:3": (1472, 1140), "3:4": (1140, 1472) } prompt = "一只可爱的小猫坐在花园里" # Chinese prompt prompt = rewrite(prompt) # Enhance prompt automatically width, height = aspect_ratios["16:9"] image = pipe( prompt=prompt, width=width, height=height, num_inference_steps=50, true_cfg_scale=4.0, generator=torch.Generator(device="cuda").manual_seed(42) ).images[0] image.save("example.png") ``` -------------------------------- ### Load and Use Qwen-Image-Edit-2509 Pipeline Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Loads the QwenImageEditPlusPipeline, processes two input images with a given prompt, and saves the output. Ensure you have the necessary libraries installed and a CUDA-enabled GPU for optimal performance. ```python import os import torch from PIL import Image from diffusers import QwenImageEditPlusPipeline from io import BytesIO import requests pipeline = QwenImageEditPlusPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509", torch_dtype=torch.bfloat16) print("pipeline loaded") pipeline.to('cuda') pipeline.set_progress_bar_config(disable=None) image1 = Image.open(BytesIO(requests.get("https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/edit2509/edit2509_1.jpg").content)) image2 = Image.open(BytesIO(requests.get("https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/edit2509/edit2509_2.jpg").content)) prompt = "The magician bear is on the left, the alchemist bear is on the right, facing each other in the central park square." inputs = { "image": [image1, image2], "prompt": prompt, "generator": torch.manual_seed(0), "true_cfg_scale": 4.0, "negative_prompt": " ", "num_inference_steps": 40, "guidance_scale": 1.0, "num_images_per_prompt": 1, } with torch.inference_mode(): output = pipeline(**inputs) output_image = output.images[0] output_image.save("output_image_edit_plus.png") print("image saved at", os.path.abspath("output_image_edit_plus.png")) ``` -------------------------------- ### Install Diffusers Library Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Install the latest version of the diffusers library. Ensure your transformers version is at least 4.51.3. ```bash pip install git+https://github.com/huggingface/diffusers ``` -------------------------------- ### Multi-GPU API Server Deployment Configuration Source: https://context7.com/qwenlm/qwen-image/llms.txt Configure environment variables for deploying Qwen-Image as a multi-GPU API server. Sets the number of GPUs, task queue size, and task timeout. ```bash # Set environment variables for configuration export NUM_GPUS_TO_USE=4 # Number of GPUs to use export TASK_QUEUE_SIZE=100 # Task queue size export TASK_TIMEOUT=300 # Task timeout in seconds export DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxxxxxx # For prompt enhancement # Start the Gradio demo server cd src python examples/demo.py # Output: Server starts at http://0.0.0.0:7860 with multi-GPU support ``` -------------------------------- ### Qwen-Image Pipeline for Text-to-Image Generation Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Illustrates text-to-image generation using the Qwen-Image DiffusionPipeline. It supports specifying different aspect ratios and includes positive/negative prompts. Ensure PyTorch is available and the device is set correctly. ```python from diffusers import DiffusionPipeline import torch model_name = "Qwen/Qwen-Image" # Load the pipeline if torch.cuda.is_available(): torch_dtype = torch.bfloat16 device = "cuda" else: torch_dtype = torch.float32 device = "cpu" pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype=torch_dtype).to(device) positive_magic = { "en": ", Ultra HD, 4K, cinematic composition.", # for english prompt "zh": ", 超清,4K,电影级构图." } # Generate image prompt = '''A coffee shop entrance features a chalkboard sign reading "Qwen Coffee 😊 $2 per cup," with a neon light beside it displaying "通义千问". Next to it hangs a poster showing a beautiful Chinese woman, and beneath the poster is written "π≈3.1415926-53589793-23846264-33832795-02384197".''' negative_prompt = " " # Recommended if you don't use a negative prompt. # Generate with different aspect ratios aspect_ratios = { "1:1": (1328, 1328), "16:9": (1664, 928), "9:16": (928, 1664), "4:3": (1472, 1104), "3:4": (1104, 1472), "3:2": (1584, 1056), "2:3": (1056, 1584), } width, height = aspect_ratios["16:9"] image = pipe( prompt=prompt + positive_magic["en"], negative_prompt=negative_prompt, width=width, height=height, num_inference_steps=50, true_cfg_scale=4.0, generator=torch.Generator(device="cuda").manual_seed(42) ).images[0] image.save("example.png") ``` -------------------------------- ### Configure Multi-GPU API Server Environment Variables Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Sets environment variables to configure the Multi-GPU API Server for Qwen-Image, controlling the number of GPUs, task queue size, and task timeout. ```bash export NUM_GPUS_TO_USE=4 # Number of GPUs to use export TASK_QUEUE_SIZE=100 # Task queue size export TASK_TIMEOUT=300 # Task timeout in seconds ``` -------------------------------- ### Text to Image Generation with Qwen-Image-2512 Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Load the QwenImagePipeline and generate an image from a detailed text prompt. Supports various aspect ratios and custom inference steps. Ensure CUDA is available for optimal performance. ```python from diffusers import QwenImagePipeline import torch # Load the pipeline if torch.cuda.is_available(): torch_dtype = torch.bfloat16 device = "cuda" else: torch_dtype = torch.float32 device = "cpu" pipe = QwenImagePipeline.from_pretrained("Qwen/Qwen-Image-2512", torch_dtype=torch_dtype).to(device) # Generate image prompt = '''A 20-year-old East Asian girl with delicate, charming features and large, bright brown eyes—expressive and lively, with a cheerful or subtly smiling expression. Her naturally wavy long hair is either loose or tied in twin ponytails. She has fair skin and light makeup accentuating her youthful freshness. She wears a modern, cute dress or relaxed outfit in bright, soft colors—lightweight fabric, minimalist cut. She stands indoors at an anime convention, surrounded by banners, posters, or stalls. Lighting is typical indoor illumination—no staged lighting—and the image resembles a casual iPhone snapshot: unpretentious composition, yet brimming with vivid, fresh, youthful charm.''' negative_prompt = "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲。" # Generate with different aspect ratios aspect_ratios = { "1:1": (1328, 1328), "16:9": (1664, 928), "9:16": (928, 1664), "4:3": (1472, 1104), "3:4": (1104, 1472), "3:2": (1584, 1056), "2:3": (1056, 1584), } width, height = aspect_ratios["16:9"] image = pipe( prompt=prompt, negative_prompt=negative_prompt, width=width, height=height, num_inference_steps=50, true_cfg_scale=4.0, generator=torch.Generator(device="cuda").manual_seed(42) ).images[0] image.save("example.png") ``` -------------------------------- ### Command-Line Generation with Prompt Enhancement Source: https://context7.com/qwenlm/qwen-image/llms.txt Run image generation from the command line with automatic prompt enhancement. Requires DASHSCOPE_API_KEY to be set for prompt rewriting. ```bash # Set API key for prompt enhancement export DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxxxxxxxxx # Run the generation script cd src python examples/generate_w_prompt_enhance.py # The script: # 1. Loads Qwen-Image pipeline # 2. Takes a simple prompt # 3. Automatically enhances it via Qwen-Plus API # 4. Generates and saves the image as example.png ``` -------------------------------- ### Qwen-Image-Edit-2511 Pipeline for Image Editing Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Demonstrates how to use the QwenImageEditPlusPipeline for image editing with support for multiple image inputs and improved consistency. Ensure the model is loaded and moved to the appropriate device (e.g., 'cuda'). ```python import os import torch from PIL import Image from diffusers import QwenImageEditPlusPipeline from io import BytesIO import requests pipeline = QwenImageEditPlusPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2511", torch_dtype=torch.bfloat16) print("pipeline loaded") pipeline.to('cuda') pipeline.set_progress_bar_config(disable=None) image1 = Image.open(BytesIO(requests.get("https://qianwen-res.oss-accelerate-overseas.aliyuncs.com/Qwen-Image/edit2511/edit2511input.png").content)) prompt = "这个女生看着面前的电视屏幕,屏幕上面写着“阿里巴巴”" inputs = { "image": [image1], "prompt": prompt, "generator": torch.manual_seed(0), "true_cfg_scale": 4.0, "negative_prompt": " ", "num_inference_steps": 40, "guidance_scale": 1.0, "num_images_per_prompt": 1, } with torch.inference_mode(): output = pipeline(**inputs) output_image = output.images[0] output_image.save("output_image_edit_2511.png") print("image saved at", os.path.abspath("output_image_edit_2511.png")) ``` -------------------------------- ### Qwen-Image-Edit Pipeline for Single Image Editing Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Shows how to use the QwenImageEditPipeline for editing a single image. It's recommended to use Qwen-Image-Edit-2509 for better consistency. Prompt rewriting is strongly recommended for stable editing results. ```python import os from PIL import Image import torch from diffusers import QwenImageEditPipeline pipeline = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit") print("pipeline loaded") pipeline.to(torch.bfloat16) pipeline.to("cuda") pipeline.set_progress_bar_config(disable=None) image = Image.open("./input.png").convert("RGB") prompt = "Change the rabbit's color to purple, with a flash light background." inputs = { "image": image, "prompt": prompt, "generator": torch.manual_seed(0), "true_cfg_scale": 4.0, "negative_prompt": " ", "num_inference_steps": 50, } with torch.inference_mode(): output = pipeline(**inputs) output_image = output.images[0] output_image.save("output_image_edit.png") print("image saved at", os.path.abspath("output_image_edit.png")) ``` -------------------------------- ### Integrate Prompt Enhancement for Text-to-Image Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Integrates the official Prompt Enhancement Tool for optimized prompts and multi-language support in text-to-image generation. Requires the 'tools.prompt_utils' module. ```python from tools.prompt_utils import rewrite prompt = rewrite(prompt) ``` -------------------------------- ### Load and Use QwenImageEditPlusPipeline for Single Image Editing Source: https://context7.com/qwenlm/qwen-image/llms.txt Loads the QwenImageEditPlusPipeline for single image editing. Ensure the model name and torch_dtype are correctly specified. The pipeline is moved to CUDA for accelerated processing. ```python pipeline = QwenImageEditPlusPipeline.from_pretrained( "Qwen/Qwen-Image-Edit-2511", torch_dtype=torch.bfloat16 ) print("pipeline loaded") pipeline.to('cuda') pipeline.set_progress_bar_config(disable=None) # Load input image image1 = Image.open(BytesIO(requests.get( "https://qianwen-res.oss-accelerate-overseas.aliyuncs.com/Qwen-Image/edit2511/edit2511input.png" ).content)) # Define edit instruction (supports Chinese and English) prompt = "这个女生看着面前的电视屏幕,屏幕上面写着"阿里巴巴"" # Configure generation parameters inputs = { "image": [image1], "prompt": prompt, "generator": torch.manual_seed(0), "true_cfg_scale": 4.0, "negative_prompt": " ", "num_inference_steps": 40, "guidance_scale": 1.0, "num_images_per_prompt": 1, } # Generate edited image with torch.inference_mode(): output = pipeline(**inputs) output_image = output.images[0] output_image.save("output_image_edit_2511.png") print("image saved at", os.path.abspath("output_image_edit_2511.png")) ``` -------------------------------- ### Prompt Enhancement for Text-to-Image Generation Source: https://context7.com/qwenlm/qwen-image/llms.txt Utilizes the prompt rewriting utility powered by Qwen-Plus to optimize prompts for text-to-image generation. The utility automatically detects language and applies enhancement strategies. Requires initializing the DiffusionPipeline and moving it to CUDA. ```python from tools.prompt_utils import rewrite from diffusers import DiffusionPipeline import torch # Initialize the pipeline pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=torch.bfloat16) pipe = pipe.to("cuda") # Available aspect ratios aspect_ratios = { "1:1": (1328, 1328), "16:9": (1664, 928), "9:16": (928, 1664), "4:3": (1472, 1140), "3:4": (1140, 1472) } # Original simple prompt (Chinese) prompt = "一只可爱的小猫坐在花园里" ``` -------------------------------- ### Text-to-Image Generation with Original Qwen-Image Model Source: https://context7.com/qwenlm/qwen-image/llms.txt Generates images using the original Qwen-Image model via the DiffusionPipeline. This method supports basic text-to-image generation and various aspect ratios. Magic suffixes can enhance prompt quality. ```python from diffusers import DiffusionPipeline import torch model_name = "Qwen/Qwen-Image" # Load the pipeline if torch.cuda.is_available(): torch_dtype = torch.bfloat16 device = "cuda" else: torch_dtype = torch.float32 device = "cpu" pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype=torch_dtype).to(device) # Magic suffixes to enhance prompt quality positive_magic = { "en": ", Ultra HD, 4K, cinematic composition.", "zh": ", 超清,4K,电影级构图." } # Generate image with text rendering prompt = '''A coffee shop entrance features a chalkboard sign reading "Qwen Coffee 😊 $2 per cup," with a neon light beside it displaying "通义千问". Next to it hangs a poster showing a beautiful Chinese woman, and beneath the poster is written "π≈3.1415926-53589793-23846264-33832795-02384197".''' negative_prompt = " " # Recommended if you don't use a negative prompt aspect_ratios = { "1:1": (1328, 1328), "16:9": (1664, 928), "9:16": (928, 1664), "4:3": (1472, 1104), "3:4": (1104, 1472), } width, height = aspect_ratios["16:9"] image = pipe( prompt=prompt + positive_magic["en"], negative_prompt=negative_prompt, width=width, height=height, num_inference_steps=50, true_cfg_scale=4.0, generator=torch.Generator(device="cuda").manual_seed(42) ).images[0] image.save("coffee_shop.png") # Output: Image with accurately rendered English, Chinese text, and mathematical symbols ``` -------------------------------- ### Text-to-Image Generation with Qwen-Image-2512 Source: https://context7.com/qwenlm/qwen-image/llms.txt Generates high-quality images from text prompts using the Qwen-Image-2512 model. Load the pipeline with bfloat16 for GPU efficiency and specify desired aspect ratios. Ensure CUDA is available for optimal performance. ```python from diffusers import QwenImagePipeline import torch # Load the pipeline with bfloat16 for GPU efficiency if torch.cuda.is_available(): torch_dtype = torch.bfloat16 device = "cuda" else: torch_dtype = torch.float32 device = "cpu" pipe = QwenImagePipeline.from_pretrained("Qwen/Qwen-Image-2512", torch_dtype=torch_dtype).to(device) # Define prompt and negative prompt prompt = '''A 20-year-old East Asian girl with delicate, charming features and large, bright brown eyes—expressive and lively, with a cheerful or subtly smiling expression. Her naturally wavy long hair is either loose or tied in twin ponytails. She has fair skin and light makeup accentuating her youthful freshness.''' negative_prompt = "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲。" # Available aspect ratios with optimal dimensions aspect_ratios = { "1:1": (1328, 1328), "16:9": (1664, 928), "9:16": (928, 1664), "4:3": (1472, 1104), "3:4": (1104, 1472), "3:2": (1584, 1056), "2:3": (1056, 1584), } width, height = aspect_ratios["16:9"] # Generate the image image = pipe( prompt=prompt, negative_prompt=negative_prompt, width=width, height=height, num_inference_steps=50, true_cfg_scale=4.0, generator=torch.Generator(device="cuda").manual_seed(42) ).images[0] image.save("generated_image.png") # Output: A high-quality 1664x928 image saved to generated_image.png ``` -------------------------------- ### Integrate Prompt Enhancement for Image Edit Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Integrates the official Prompt Enhancement Tool for enhanced stability in image editing tasks. Requires the 'tools.prompt_utils' module and a PIL image object. ```python from tools.prompt_utils import polish_edit_prompt prompt = polish_edit_prompt(prompt, pil_image) ``` -------------------------------- ### Rewrite Prompt for Enhanced Quality Source: https://context7.com/qwenlm/qwen-image/llms.txt Rewrite a given prompt to improve image generation quality. Requires the DASHSCOPE_API_KEY environment variable to be set. ```python # export DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxxxxxxxxx prompt = rewrite(prompt) print(f"Enhanced prompt: {prompt}") width, height = aspect_ratios["16:9"] image = pipe( prompt=prompt, width=width, height=height, num_inference_steps=50, true_cfg_scale=4.0, generator=torch.Generator(device="cuda").manual_seed(42) ).images[0] image.save("example.png") # Output: High-quality image generated from enhanced prompt with additional visual details ``` -------------------------------- ### Generate Image with SGLang Source: https://github.com/qwenlm/qwen-image/blob/main/README.md Use this command to generate or edit images with Qwen-Image using SGLang. Specify the model path, prompt, and image paths for editing tasks. ```bash sglang generate --model-path Qwen/Qwen-Image-Edit-2511 --prompt "make the girl in Figure 1 dance with the capybara in Figure 2." --image-path "https://github.com/lm-sys/lm-sys.github.io/releases/download/test/TI2I_Qwen_Image_Edit_Input.jpg" "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/edit2509/edit2509_2.jpg" ``` -------------------------------- ### Prompt Enhancement for Image Editing Source: https://context7.com/qwenlm/qwen-image/llms.txt Enhance edit prompts using the vision-language model for more specific editing instructions based on image context. Requires DASH_API_KEY environment variable. ```python from tools.prompt_utils import polish_edit_prompt from PIL import Image from diffusers import QwenImageEditPipeline import torch # Load the editing pipeline pipeline = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit") pipeline.to(torch.bfloat16) pipeline.to("cuda") # Load input image pil_image = Image.open("./portrait.png").convert("RGB") # Original simple edit instruction original_prompt = "Change the person's hat" # Enhance the edit prompt (requires DASH_API_KEY environment variable) # export DASH_API_KEY=sk-xxxxxxxxxxxxxxxxxxxx enhanced_prompt = polish_edit_prompt(original_prompt, pil_image) print(f"Enhanced prompt: {enhanced_prompt}") # Example output: "Replace the man's hat with a dark brown beret; keep smile, short hair, and gray jacket unchanged" # Generate edited image with enhanced prompt inputs = { "image": pil_image, "prompt": enhanced_prompt, "generator": torch.manual_seed(0), "true_cfg_scale": 4.0, "negative_prompt": " ", "num_inference_steps": 50, } with torch.inference_mode(): output = pipeline(**inputs) output_image = output.images[0] output_image.save("edited_portrait.png") # Output: More accurate edit with preserved identity features ``` -------------------------------- ### Multi-Image Editing with Qwen-Image-Edit-2509 Source: https://context7.com/qwenlm/qwen-image/llms.txt Combines multiple input images into a single output using the Qwen-Image-Edit-2509 model. Supports various combinations like person+person, person+scene, and person+object with up to 3 images. ```python import os import torch from PIL import Image from diffusers import QwenImageEditPlusPipeline from io import BytesIO import requests # Load the multi-image editing pipeline pipeline = QwenImageEditPlusPipeline.from_pretrained( "Qwen/Qwen-Image-Edit-2509", torch_dtype=torch.bfloat16 ) print("pipeline loaded") pipeline.to('cuda') pipeline.set_progress_bar_config(disable=None) # Load multiple input images image1 = Image.open(BytesIO(requests.get( "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/edit2509/edit2509_1.jpg" ).content)) image2 = Image.open(BytesIO(requests.get( "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/edit2509/edit2509_2.jpg" ).content)) # Describe how to combine the images prompt = "The magician bear is on the left, the alchemist bear is on the right, facing each other in the central park square." inputs = { "image": [image1, image2], # List of input images "prompt": prompt, "generator": torch.manual_seed(0), "true_cfg_scale": 4.0, "negative_prompt": " ", "num_inference_steps": 40, "guidance_scale": 1.0, "num_images_per_prompt": 1, } with torch.inference_mode(): output = pipeline(**inputs) output_image = output.images[0] output_image.save("output_image_edit_plus.png") print("image saved at", os.path.abspath("output_image_edit_plus.png")) ``` -------------------------------- ### Single Image Editing with Qwen-Image-Edit Source: https://context7.com/qwenlm/qwen-image/llms.txt Performs single-image editing operations like style transfer, object modification, text editing, and background changes using the original Qwen-Image-Edit model. The image is loaded and converted to RGB before processing. ```python import os from PIL import Image import torch from diffusers import QwenImageEditPipeline # Load the single-image editing pipeline pipeline = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit") print("pipeline loaded") pipeline.to(torch.bfloat16) pipeline.to("cuda") pipeline.set_progress_bar_config(disable=None) # Load input image image = Image.open("./input.png").convert("RGB") # Define edit instruction prompt = "Change the rabbit's color to purple, with a flash light background." inputs = { "image": image, "prompt": prompt, "generator": torch.manual_seed(0), "true_cfg_scale": 4.0, "negative_prompt": " ", "num_inference_steps": 50, } with torch.inference_mode(): output = pipeline(**inputs) output_image = output.images[0] output_image.save("output_image_edit.png") print("image saved at", os.path.abspath("output_image_edit.png")) ``` -------------------------------- ### Image Editing with Qwen-Image-Edit-2511 Source: https://context7.com/qwenlm/qwen-image/llms.txt Edits existing images using natural language instructions with the Qwen-Image-Edit-2511 model. This model supports multi-image input, improved character consistency, and built-in LoRA capabilities. ```python import os import torch from PIL import Image from diffusers import QwenImageEditPlusPipeline from io import BytesIO import requests ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.