From ec8ff95e221106f0232a58ffdc1b3be1ba3bad55 Mon Sep 17 00:00:00 2001 From: Zhou Taichang Date: Mon, 5 Jan 2026 14:17:08 +0800 Subject: [PATCH] Dev/add i2i bash (#623) Signed-off-by: tzhouam Signed-off-by: Zhou Taichang --- .../image_to_image/run_curl_image_edit.sh | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 examples/online_serving/image_to_image/run_curl_image_edit.sh diff --git a/examples/online_serving/image_to_image/run_curl_image_edit.sh b/examples/online_serving/image_to_image/run_curl_image_edit.sh new file mode 100644 index 000000000..748a0ebe5 --- /dev/null +++ b/examples/online_serving/image_to_image/run_curl_image_edit.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# Qwen-Image image-edit (image-to-image) curl example + +set -euo pipefail + +if [[ $# -lt 2 ]]; then + echo "Usage: $0 \"\" [output_file]" >&2 + exit 1 +fi + +INPUT_IMG=$1 +PROMPT=$2 +SERVER="${SERVER:-http://localhost:8092}" +CURRENT_TIME=$(date +%Y%m%d%H%M%S) +OUTPUT="${3:-image_edit_${CURRENT_TIME}.png}" + +if [[ ! -f "$INPUT_IMG" ]]; then + echo "Input image not found: $INPUT_IMG" >&2 + exit 1 +fi + +IMG_B64=$(base64 -w0 "$INPUT_IMG") + +REQUEST_JSON=$( + jq -n --arg prompt "$PROMPT" --arg img "$IMG_B64" '{ + messages: [{ + role: "user", + content: [ + {"type": "text", "text": $prompt}, + {"type": "image_url", "image_url": {"url": ("data:image/png;base64," + $img)}} + ] + }], + extra_body: { + height: 1024, + width: 1024, + num_inference_steps: 50, + guidance_scale: 1, + seed: 42 + } + }' +) + +echo "Generating edited image..." +echo "Server: $SERVER" +echo "Prompt: $PROMPT" +echo "Input : $INPUT_IMG" +echo "Output: $OUTPUT" + +curl -s "$SERVER/v1/chat/completions" \ + -H "Content-Type: application/json" \ + -d "$REQUEST_JSON" \ + | jq -r '.choices[0].message.content[0].image_url.url' \ + | cut -d',' -f2 \ + | base64 -d > "$OUTPUT" + +if [[ -f "$OUTPUT" ]]; then + echo "Image saved to: $OUTPUT" + echo "Size: $(du -h "$OUTPUT" | cut -f1)" +else + echo "Failed to generate image" + exit 1 +fi