SophNet Image Edit
Overview
Edit existing images with Python scripts that handle task polling and structured output.
Script responsibilities:
edit_image.py: core API caller and polling loop, outputsINPUT_IMAGE_COUNT,TASK_ID,STATUS, andIMAGE_URL.edit_and_preview.sh: wrapper for local use, callsedit_image.py, downloads first result, addsPREVIEW_PATH.
When to Use
- User asks to edit or transform existing images with Sophnet.
- Task uses one or more source images (URL or uploaded local files).
- Task depends on image order/role, such as:
- put part of image-2 into image-1
- render image-2 with image-1 style
- blend/composite many images into one result
- Do not use when the task is pure text-to-image generation; use
sophnet-image-generate.
Image Path Resolution
When users upload images in chat channels, files are usually saved under media/inbound/images/ in the workspace. Use Media Understanding logs to get exact resolved paths.
Typical log pattern:
[Media Understanding] Resolved relative path: "media/inbound/images/xxx.jpg" -> "/absolute/path/to/workspace/media/inbound/images/xxx.jpg"
Path rules:
--imageaccepts URL, data URI, or local file path.- Local file paths are auto-converted to data URI by the script.
- For multi-image tasks, pass every image explicitly and in required order.
Multi-Image Rules
- Keep source image order stable and explicit.
- Bind prompt language to order (image-1, image-2, image-3...).
- Do not drop "reference" images; pass all images used by the prompt.
- Verify script output
INPUT_IMAGE_COUNTequals expected image count before trusting results.
Recommended prompt pattern for multi-image tasks:
图1作为底图,图2提供主体元素,图3提供风格参考;将图2主体抠出放到图1右上角,并按图3风格整体渲染。
Quick Reference
| Goal | Command |
| --- | --- |
| Edit with one source | bash {baseDir}/scripts/edit_and_preview.sh --prompt "..." --image "https://example.com/source.jpg" |
| Edit with two sources (ordered) | bash {baseDir}/scripts/edit_and_preview.sh --prompt "图1作为底图,将图2主体放入图1左下角" --image "media/inbound/images/img1.jpg" --image "media/inbound/images/img2.jpg" |
| Style transfer across two images | uv run --project {baseDir} python {baseDir}/scripts/edit_image.py --prompt "使用图1的画风渲染图2内容" --image "/abs/path/style.jpg" --image "/abs/path/content.jpg" |
| Many images via CSV | uv run --project {baseDir} python {baseDir}/scripts/edit_image.py --prompt "..." --images "media/inbound/images/a.jpg,media/inbound/images/b.jpg,https://example.com/c.jpg" |
| Many images via list file | uv run --project {baseDir} python {baseDir}/scripts/edit_image.py --prompt "..." --images-file "/tmp/image-list.txt" |
| Validate image count only | uv run --project {baseDir} python {baseDir}/scripts/edit_image.py --prompt "..." --images-file "/tmp/image-list.txt" --dry-run |
| Show options | uv run --project {baseDir} python {baseDir}/scripts/edit_image.py --help |
Notes:
--dry-rundoes not require API key and is for input-count verification only.- Prefer
--images-filewhen handling many images or values that may contain commas.
/tmp/image-list.txt format example:
# One image reference per line
media/inbound/images/base.jpg
media/inbound/images/object.png
https://example.com/style.jpg
Script Output Fields
The script outputs structured key=value lines. Parse all of them:
| Field | Description |
| --- | --- |
| INPUT_IMAGE_COUNT | Number of source images passed to the API |
| TASK_ID | API task identifier |
| STATUS | succeeded or failed |
| OUTPUT_COUNT | Number of result images |
| IMAGE_URL | Publicly accessible signed URL for each result image |
| PREVIEW_PATH | Local file path (only when OSS re-upload failed as fallback) |
Presenting Results to Users
After a successful edit, present the results with context -- not just a bare URL. Include:
- What was done: mention the edit instruction / style applied.
- Input/output image counts.
- The result image URL(s): provide the
IMAGE_URLso the user can view/download. - If
PREVIEW_PATHis present, mention the local file path.
Example response pattern:
图片编辑完成!
- 编辑指令:把图片变成水彩画风格
- 输入图片数:1
- 结果图片:<IMAGE_URL>
Implementation
- Resolve all uploaded image paths from Media Understanding logs.
- If this edit step follows
sophnet-image-generate, prefer upstreamIMAGE_URLfor handoff; usePREVIEW_PATHonly when local-file input is explicitly intended. - Build prompt with explicit image order semantics.
- Run script with one
--imageper image, or--images, or--images-file. - For multi-image tasks, run once with
--dry-runand confirmINPUT_IMAGE_COUNTmatches intended image count. - Parse ALL output fields (see table above) and present them to the user.
- Use
PREVIEW_PATHwhen present.
API payload shape:
model:Qwen-Image-Edit-2509input.prompt: edit instruction with image-role semanticsinput.images[]: all source image refs in strict orderparameters:size,n,watermark
Common Mistakes
- Passing only one image for a multi-image prompt.
- Mentioning image-2/image-3 in prompt but not passing those images.
- Reordering
--imagearguments unintentionally. - Ignoring
INPUT_IMAGE_COUNTmismatch. - Using non-existent local paths.
- In generate→edit workflows, defaulting to
PREVIEW_PATHinstead ofIMAGE_URLwithout reason. - Only showing a bare URL without context -- always present a summary with edit details.
微信扫一扫