Gradio Workflow 实战:把模型、Space 与 GPU 串成可部署的 AI 工作流
Wire It, Run It, Deploy It: AI Workflows in Gradio
Gradio 的 gr.Workflow 让用户用画布把引用、算子、输出三类节点连成图,算子可以是自写 Python 函数、Hugging Face Inference Providers 上的模型、其他 Gradio Space 或 Hub 数据集的一行。文中演示了调用 Qwen-Image-Edit 的图片编辑、串联 FLUX 与背景移除 Space 的媒体工作室、并行生成多风格图像的 Generative Art Lab,以及用 @spaces.GPU 在 ZeroGPU 上跑 Lightricks/LTX-Video 的动画应用。每个输出都会自动生成同名 REST 端点,可直接用 Gradio 客户端或 curl 调用。
正文
当前显示原文,中文全文译文尚未就绪。
Edit an Image
Upload an image, type an edit ("turn it into a snowy winter scene", "add sunglasses", "make the car red"), and get the edited photo back. The whole app is a single node calling Qwen-Image-Edit on Hugging Face Inference Providers.
👉 Try the Image Editor Pipeline
Chain real models into a media studio
One graph, three pipelines. Start with a prompt and generate an image with FLUX , then pass it to a background-removal Gradio Space to turn it into a sticker. A topic becomes a voiceover through a text-to-speech Gradio Space , while the same topic becomes a catchy episode title through an LLM call.
That’s one canvas, two model calls through Hugging Face Inference Providers , and two calls to Gradio Spaces.
Since this is a workflow, each of the three outputs also gets its own REST endpoint: /sticker , /voiceover , and /episode_title . You can call any of them directly from code without opening the UI. See Call it from code below for a runnable example.
👉 Try the AI Media Studio
Fan-out image generation in parallel
Type in one idea, and it turns into a set of generated artwork all at once: a base image from FLUX, two AI re-imaginings of that image (a soft watercolor version and a neon cyberpunk take), and a gallery title written by an LLM.
Each image is generated directly from the prompt by a model node using Inference Providers, while the title comes from an fn node that calls an LLM. This is the fan-out pattern in action: one idea can feed multiple operators simultaneously, all generating in parallel.
👉 Try the Generative Art Lab
Profile a Hugging Face dataset
Type in a Hugging Face dataset ID, such as stanfordnlp/imdb or mteb/tweet_sentiment_extraction , and a single input fans out to four operator nodes that analyze the dataset live using the Datasets Server API.
You get an overview card, a preview of the first few rows, per-column statistics, and a distribution chart, all computed independently and in parallel. That’s the power of workflows!
👉 Try Data Detective
Run your own GPU model
Every node so far reaches out to Hugging Face. But an fn node is just Python, which means it can also run a model inside the Space on a GPU.
Decorate the bound function with @spaces.GPU and, when the node runs, ZeroGPU grabs a GPU for that call, runs the model, and releases it. We don't always need to rely on Inference Providers or existing Gradio Spaces.
Check out this demo that animates a still image using Lightricks/LTX-Video loaded through Diffusers, running entirely through one node. gr.Workflow doesn't need to know anything about your GPU setup. It simply calls the bound function.
👉 Try the ZeroGPU Animator
How it works, in a nutshell
Every workflow is a graph with three kinds of nodes: references (your inputs), operators (the steps that do work), and subjects (your outputs). An operator can be your own Python function, a model on Hugging Face Inference Providers, another Gradio Space, or a row from a Hub dataset. You connect them by dragging between typed ports, hit Run, and watch each result appear in place.
Call it from code
Every workflow you build is also an API, with no extra work. Each output becomes a REST endpoint named after its label, and you can call it from Python with the Gradio client. Here is a live, no-token example against the multi-endpoint demo Space, exactly as-is:
Endpoints that call a model or a Space run under a Hugging Face token, so pass one when you create the client:
Prefer plain HTTP? Every endpoint is reachable over curl too:
Build your own
The fastest way in is to open any demo above, click Duplicate , and start rewiring. From Python, it is as short as:
For the full walkthrough, the operator kinds, the JSON schema, and reusable patterns, see the official gr.Workflow guide in the Gradio docs.
You can even build something as involved as AUTOMATIC1111 with gr.Workflow . Keep an eye out for our next post, where we walk through building it step by step. Here is a sneak peek 😉👇
Models mentioned in this article 4
Lightricks/LTX-Video-0.9.7-distilled
Qwen/Qwen-Image-Edit
Qwen/Qwen2.5-7B-Instruct
black-forest-labs/FLUX.1-schnell
Spaces mentioned in this article 6
MeloTTS
Fast, efficient, & multilingual text-to-speech
Background Removal
Remove backgrounds from images instantly
Generative Art Lab · gr.Workflow
Create multiple art styles and a title from one prompt
Data Detective · gr.Workflow
Explore Hugging Face datasets with instant visual summaries
Instruction Image Editor · gr.Workflow
Edit images with custom text instructions
ZeroGPU Animator · gr.Workflow
Animate a picture into a short video
More Articles from our Blog
Rebuilding AUTOMATIC1111 with Gradio Workflow
¡Órale! gr.Workflow de Gradio está padrísimo porque te permite armar pipelines de IA súper complejos en un lienzo interactivo sin complicarte la vida con código enredado. Es una herramienta de verdad chida para visualizar cada paso del proceso, depurar en tiempo real y desplegar tus modelos directito a Hugging Face Spaces en un dos por tres. La neta, para cualquiera que trabaje creando herramientas de IA generativa, esto viene a aligerar el trabajo un buen. https://starzbetmex.com/
+37
Models mentioned in this article 4
Lightricks/LTX-Video-0.9.7-distilled
Qwen/Qwen-Image-Edit
Qwen/Qwen2.5-7B-Instruct
black-forest-labs/FLUX.1-schnell
Spaces mentioned in this article 6
MeloTTS
Fast, efficient, & multilingual text-to-speech
Background Removal
Remove backgrounds from images instantly
Generative Art Lab · gr.Workflow
Create multiple art styles and a title from one prompt
Data Detective · gr.Workflow
Explore Hugging Face datasets with instant visual summaries
Instruction Image Editor · gr.Workflow
Edit images with custom text instructions