Files
vllm-omni/docs/user_guide/examples/online_serving/image_to_image.md
T
2025-12-17 17:40:45 +08:00

4.5 KiB

Qwen-Image-Edit Online Serving

Source https://github.com/vllm-project/vllm-omni/tree/main/examples/online_serving/qwen_image_edit.

This example demonstrates how to deploy Qwen-Image-Edit model for online image editing service using vLLM-Omni.

Start Server

Basic Start

vllm serve Qwen/Qwen-Image-Edit --omni --port 8092

Start with Parameters

Or use the startup script:

bash run_server.sh

API Calls

Method 1: Using curl (Image Editing)

# Image editing
bash run_curl_image_edit.sh input.png "Convert this image to watercolor style"

# Or execute directly
IMG_B64=$(base64 -w0 input.png)
curl -s http://localhost:8092/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d "{
    \"messages\": [{
      \"role\": \"user\",
      \"content\": [
        {\"type\": \"text\", \"text\": \"Convert this image to watercolor style\"},
        {\"type\": \"image_url\", \"image_url\": {\"url\": \"data:image/png;base64,\$IMG_B64\"}}
      ]
    }],
    \"extra_body\": {
      \"height\": 1024,
      \"width\": 1024,
      \"num_inference_steps\": 50,
      \"guidance_scale\": 7.5,
      \"seed\": 42
    }
  }" | jq -r '.choices[0].message.content[0].image_url.url' | cut -d',' -f2 | base64 -d > output.png

Method 2: Using Python Client

python openai_chat_client.py --input input.png --prompt "Convert to oil painting style" --output output.png

Method 3: Using Gradio Demo

python gradio_demo.py
# Visit http://localhost:7861

Request Format

Image Editing (Using image_url Format)

{
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "Convert this image to watercolor style"},
        {"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}
      ]
    }
  ]
}

Image Editing (Using Simplified image Format)

{
  "messages": [
    {
      "role": "user",
      "content": [
        {"text": "Convert this image to watercolor style"},
        {"image": "BASE64_IMAGE_DATA"}
      ]
    }
  ]
}

Image Editing with Parameters

Use extra_body to pass generation parameters:

{
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "Convert to ink wash painting style"},
        {"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}
      ]
    }
  ],
  "extra_body": {
    "height": 1024,
    "width": 1024,
    "num_inference_steps": 50,
    "guidance_scale": 7.5,
    "seed": 42
  }
}

Generation Parameters (extra_body)

Parameter Type Default Description
num_inference_steps int 50 Number of denoising steps
guidance_scale float 7.5 CFG guidance scale
seed int None Random seed (reproducible)
negative_prompt str None Negative prompt
num_outputs_per_prompt int 1 Number of images to generate

Response Format

{
  "id": "chatcmpl-xxx",
  "created": 1234567890,
  "model": "Qwen/Qwen-Image-Edit",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": [{
        "type": "image_url",
        "image_url": {
          "url": "data:image/png;base64,..."
        }
      }]
    },
    "finish_reason": "stop"
  }],
  "usage": {...}
}

Common Editing Instructions Examples

Instruction Description
Convert this image to watercolor style Style transfer
Convert the image to black and white Desaturation
Enhance the color saturation Color adjustment
Convert to cartoon style Cartoonization
Add vintage filter effect Filter effect
Convert daytime scene to nighttime Scene conversion

File Description

File Description
run_server.sh Server startup script
run_curl_image_edit.sh curl image editing example
openai_chat_client.py Python client
gradio_demo.py Gradio interactive interface

Example materials

??? abstract "gradio_demo.py" py --8<-- "examples/online_serving/qwen_image_edit/gradio_demo.py" ??? abstract "openai_chat_client.py" py --8<-- "examples/online_serving/qwen_image_edit/openai_chat_client.py" ??? abstract "run_curl_image_edit.sh" sh --8<-- "examples/online_serving/qwen_image_edit/run_curl_image_edit.sh" ??? abstract "run_server.sh" sh --8<-- "examples/online_serving/qwen_image_edit/run_server.sh"