Rebuilding AUTOMATIC1111 with Gradio Workflow
Rebuilding AUTOMATIC1111 with Gradio Workflow
使用 Gradio Workflow 重构 AUTOMATIC1111
In our last post, we built five small gr.Workflow graphs and hinted at what it would take to build something as complex as AUTOMATIC1111’s stable-diffusion-webui. In this post we walk you through Workflow1111, where we have rebuilt most of AUTOMATIC1111’s feature set as a single workflow canvas.
在上一篇文章中,我们构建了五个小型 gr.Workflow 图,并暗示了构建像 AUTOMATIC1111 的 stable-diffusion-webui 这样复杂的系统需要什么。在本文中,我们将带您了解 Workflow1111,我们已将 AUTOMATIC1111 的大部分功能集重构为一个单一的工作流画布。
Workflow1111 is a graph of eleven media pipelines built using seventy-three nodes. It brings together SOTA models for text-to-image, hi-resolution fix, image-to-image, prompt-matrix grids, VLM interrogate, detection-to-inpaint masks, ControlNet-style annotators, background removal, PNG Info storing, and image-to-video.
Workflow1111 是一个由 73 个节点构建的包含 11 个媒体流水线的图。它汇集了用于文生图、高分辨率修复、图生图、提示词矩阵网格、VLM 询问、检测转重绘蒙版、ControlNet 风格标注器、背景移除、PNG 信息存储和图生视频的 SOTA(最先进)模型。
You can run any of these pipelines by signing in with your Hugging Face account or providing an access token. Once you sign in, the model calls use your own quota. 👉 Try Workflow1111, or duplicate the Space and start rewiring it for your own use case. Let’s walk the canvas.
您可以通过登录 Hugging Face 账户或提供访问令牌来运行这些流水线。登录后,模型调用将使用您自己的配额。👉 尝试 Workflow1111,或者复制该 Space 并开始根据您的用例重新连接它。让我们浏览一下画布。
What’s on the canvas
画布上有什么
All the media pipelines are built from the same four operator kinds covered in our last post and the official guide. Each node on the canvas wraps one operator, and the operator’s inputs and outputs become the ports you connect edges to. As a quick reference on our four operator kinds: fn is a Python function, model is a model called through InferenceClient, space is another Gradio Space, and dataset is a row from a Hub dataset.
所有的媒体流水线都是由我们在上一篇文章和官方指南中介绍的四种运算符构建的。画布上的每个节点都封装了一个运算符,运算符的输入和输出成为您连接边的端口。关于我们四种运算符的快速参考:fn 是 Python 函数,model 是通过 InferenceClient 调用的模型,space 是另一个 Gradio Space,dataset 是 Hub 数据集中的一行数据。
Text-to-image
文生图
This is the core pipeline. It has the controls you’d expect from A1111’s txt2img tab: negative prompt, steps, CFG, seed, width and height, plus a model_id field for choosing the checkpoint. The prompt goes through a prompt-builder fn node first, which appends the selected style preset and cleans up the text, then into a model node that calls the checkpoint through Inference Providers. A post-process fn node writes the generation parameters into the PNG’s metadata on the way out, which is what the PNG Info pipeline reads back later.
这是核心流水线。它具有您在 A1111 的 txt2img 选项卡中所期望的控件:负面提示词、步数、CFG、种子、宽度和高度,以及用于选择检查点(checkpoint)的 model_id 字段。提示词首先通过一个 prompt-builder fn 节点,该节点会附加选定的风格预设并清理文本,然后进入一个通过推理提供商(Inference Providers)调用检查点的 model 节点。一个后处理 fn 节点在输出时将生成参数写入 PNG 的元数据中,这正是 PNG Info 流水线稍后读取的内容。
Hi-resolution fix
高分辨率修复
In Automatic1111, hi-resolution fix first upscales the txt2img output and then runs a second denoising pass. Here it’s a two-node detour instead. The text-to-image result goes into a FLUX.1-Kontext model node with a refine instruction (“enhance fine detail and micro-texture, keep the composition identical”) and comes back sharper and larger.
在 Automatic1111 中,高分辨率修复首先放大 txt2img 的输出,然后运行第二次去噪。在这里,它是一个双节点的绕道处理。文生图的结果进入一个带有细化指令(“增强细节和微纹理,保持构图不变”)的 FLUX.1-Kontext 模型节点,返回的结果更清晰、尺寸更大。
Image-to-image
图生图
That same Kontext node doubles as the image-to-image tab. Upload an image, describe the change you want, and it returns the edited image.
同一个 Kontext 节点也可以作为图生图选项卡使用。上传一张图片,描述您想要的更改,它就会返回编辑后的图片。
Let an LLM write the prompt
让 LLM 编写提示词
Start with a rough prompt like “A lighthouse in a storm.” This pipeline sends it to a Qwen3-4B model node, and a small fn node turns the reply into a clean list of tags, capped at forty: “stormy sea, wet rocks, dramatic composition, low angle shot, volumetric lighting, ominous tone.” You can connect any diffusion model node to this output to render the image. There’s no custom node involved, unlike in ComfyUI. In a Gradio workflow the LLM and the diffusion model are both ordinary model operators on the same canvas.
从一个粗略的提示词开始,例如“暴风雨中的灯塔”。该流水线将其发送到 Qwen3-4B 模型节点,一个小型的 fn 节点将回复转换为一个干净的标签列表,上限为 40 个:“波涛汹涌的大海、湿润的岩石、戏剧性的构图、低角度拍摄、体积光、不祥的基调”。您可以将任何扩散模型节点连接到此输出以渲染图像。与 ComfyUI 不同,这里不涉及自定义节点。在 Gradio 工作流中,LLM 和扩散模型都是同一画布上的普通模型运算符。
Read an image back into a prompt
将图片读取回提示词
This is like AUTOMATIC1111’s Interrogate button, with a VLM doing the interrogating instead of CLIP. Qwen2.5-VL looks at a night-market photo and writes a prompt that could have produced it. A ViT classifier node reads the same image and returns labels: restaurant 51.9%, tobacco shop 15.6%, toyshop 9.1%. Both nodes use the same image input, so gr.Workflow runs them in parallel and you get both answers in roughly the time it takes to run one.
这类似于 AUTOMATIC1111 的 Interrogate(询问)按钮,但由 VLM 而非 CLIP 来执行询问。Qwen2.5-VL 查看一张夜市照片并编写一个可能生成该照片的提示词。一个 ViT 分类器节点读取同一张图片并返回标签:餐厅 51.9%,烟草店 15.6%,玩具店 9.1%。两个节点使用相同的图像输入,因此 gr.Workflow 并行运行它们,您可以在运行一个节点所需的时间内获得两个答案。
Detection to inpaint mask
检测转重绘蒙版
AUTOMATIC1111 makes you paint an inpaint mask by hand. This pipeline generates one from a detector instead. DETR finds six objects in a street photo (three people, a dog, a bicycle, and a car), and from there the workflow splits into two branches: one draws the detected boxes on the original image, the other turns them into a mask you can feed into an inpaint pipeline downstream. The drawing and the mask creation both happen locally with Pillow and NumPy. Only the detection call leaves the machine.
AUTOMATIC1111 要求您手动绘制重绘蒙版。而此流水线则通过检测器生成蒙版。DETR 在街景照片中找到六个物体(三个人、一只狗、一辆自行车和一辆汽车),随后工作流分为两个分支:一个在原始图像上绘制检测框,另一个将其转换为可以输入到下游重绘流水线的蒙版。绘制和蒙版创建都在本地使用 Pillow 和 NumPy 完成。只有检测调用会离开本地机器。
Prompt matrix
提示词矩阵
This is like AUTOMATIC1111’s prompt matrix. A base prompt, “a lone oak tree,” gets combined with four suffixes (at sunrise, in a thunderstorm, under the Milky Way, in autumn fog) by a fn node, and each variant goes to its own text-to-image node. A final node stitches the four results into one contact sheet. gr.Workflow has no loop operator, so the four text-to-image nodes sit side by side on the canvas. Since they’re at the same dependency depth they run in parallel, and all four images start generating at once.
这类似于 AUTOMATIC1111 的提示词矩阵。一个基础提示词“一棵孤独的橡树”通过一个 fn 节点与四个后缀(日出时、雷雨中、银河下、秋雾中)组合,每个变体进入各自的文生图节点。最后一个节点将四个结果拼接成一张联系表。gr.Workflow 没有循环运算符,因此四个文生图节点并排放在画布上。由于它们处于相同的依赖深度,它们并行运行,四张图片同时开始生成。
Upscale and background removal
放大与背景移除
This is like the Extras tab in Automatic1111. There are two upscaler nodes, and they take different routes. The first is a local Lanczos resample in an fn node, which needs no network call and finishes as fast as Pillow can resize. The second is AuraSR ×4, and it’s the first space node on the canvas: it calls a Space on the Hub and treats the result like any other node output. Background removal works the same way. BRIA RMBG-2.0 is another space node, so the whole model lives in its own Space and this canvas just calls it in.
这类似于 Automatic1111 中的 Extras 选项卡。有两个放大节点,它们采用不同的路径。第一个是 fn 节点中的本地 Lanczos 重采样,不需要网络调用,完成速度与 Pillow 调整大小的速度一样快。第二个是 AuraSR ×4,它是画布上的第一个 space 节点:它调用 Hub 上的一个 Space,并将结果视为任何其他节点输出。背景移除的工作方式相同。BRIA RMBG-2.0 是另一个 space 节点,因此整个模型驻留在其自己的 Space 中,而此画布只是调用它。
Annotators
标注器
Canny, line art, sketch, luma-depth, and posterize are the preprocessors you’d normally get from the ControlNet extension in Automatic1111. Here, each one is a fn node written in plain NumPy, with no model behind it. On a pre-loaded example photo of a building facade, each annotator takes about half a second on CPU. There are 36 operator nodes in the app, 32 are fn nodes, and 22 of those run entirely in-process without a network call. Roughly two-thirds of the canvas keeps working if you lose your connection. Since these are regular Python functions, you can also test them directly, with no canvas, server, or GPU involved.
Canny、线稿、素描、亮度深度和色调分离是您通常在 Automatic1111 的 ControlNet 扩展中获得的预处理器。在这里,每一个都是用纯 NumPy 编写的 fn 节点,背后没有模型。在预加载的建筑立面示例照片上,每个标注器在 CPU 上大约需要半秒钟。该应用中有 36 个运算符节点,其中 32 个是 fn 节点,且其中 22 个完全在进程内运行,无需网络调用。如果您断开连接,大约三分之二的画布仍能正常工作。由于这些是普通的 Python 函数,您也可以直接测试它们,无需画布、服务器或 GPU。
PNG Info
PNG 信息
AUTOMATIC1111 stores generation details in the PNG’s parameters.
AUTOMATIC1111 将生成细节存储在 PNG 的参数中。