Principle:A616567126 GPT WEB JAVA SD WebUI Integration
| Knowledge Sources | |
|---|---|
| Domains | Image_Generation, API_Integration |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Integration pattern that connects to the AUTOMATIC1111 Stable Diffusion WebUI REST API for text-to-image and image-to-image generation, with Redis-based queue management and progress polling.
Description
The AUTOMATIC1111 Stable Diffusion WebUI exposes a REST API (/sdapi/v1/) for programmatic image generation. Key endpoints include txt2img, img2img, progress, png-info, and samplers.
This repository integrates with the SD WebUI as a backend service. User requests are queued in Redis, and a scheduled task processes them sequentially by calling the SD WebUI API. The prompt is translated to English before submission. Progress is polled via the /sdapi/v1/progress endpoint, which returns the current preview image and completion percentage.
Usage
Use this principle when:
- Integrating with AUTOMATIC1111 SD WebUI for image generation
- Building a queue-based image generation service
- Supporting both text-to-image and image-to-image workflows
Theoretical Basis
Generation Pipeline:
# Abstract algorithm (NOT real implementation)
def create_image(request):
# Queue the request
redis.rpush("user_queue", serialize(request))
return get_queue_position(request)
def process_queue():
if queue_length > 0:
request = deserialize(redis.lindex("user_queue", 0))
# Translate prompt
prompt_en = translate_to_english(request.prompt)
# Call SD WebUI
if request.has_init_images:
response = POST(sd_url + "/sdapi/v1/img2img", build_img2img_params(request, prompt_en))
else:
response = POST(sd_url + "/sdapi/v1/txt2img", build_txt2img_params(request, prompt_en))
# Save images
for image_base64 in response.images:
local_path = save_base64_image(image_base64)
# Deliver to user
send_message(request.user_id, result)
# Remove from queue
redis.lpop("user_queue", 0)
Key SD WebUI Endpoints:
POST /sdapi/v1/txt2img— text-to-image generationPOST /sdapi/v1/img2img— image-to-image generationGET /sdapi/v1/progress— current generation progress + previewPOST /sdapi/v1/png-info— extract parameters from generated PNGGET /sdapi/v1/samplers— list available samplers
Practical Guide
The repository implements this in SdController, QueueUtil, and MyTask:
SdController.createImage()— validates request, adds to Redis queue, returns queue positionQueueUtil.addUserToQueue()— pushes serialized request to Redis list (user_queue)MyTask.run()— scheduled every 5s, processes queue head, calls SD WebUI API, saves images, delivers resultSdController.getQueue()— polls queue position and SD progress endpointSdController.pngInfo()— extracts generation parameters from a PNG imageSdController.getModel/getLora/getSamplers()— lists available models, LoRAs, and samplers
Related Pages
Implemented By
- Implementation:A616567126_GPT_WEB_JAVA_SdController
- Implementation:A616567126_GPT_WEB_JAVA_MyTask
- Implementation:A616567126_GPT_WEB_JAVA_QueueUtil
- Implementation:A616567126_GPT_WEB_JAVA_SdConfigController