gradio

GitHub

用于构建基于Python的Gradio交互式Web UI和机器学习演示。涵盖核心API、Interface/Blocks模式、事件监听、布局控制及自定义组件开发,支持创建、修改、调试相关应用。

.agents/skills/gradio/SKILL.md gradio-app/gradio

Trigger Scenarios

需要快速搭建Python Web界面原型 构建机器学习模型演示Demo 实现交互式数据可视化面板

Install

npx skills add gradio-app/gradio --skill gradio -g -y
More Options

Non-standard path

npx skills add https://github.com/gradio-app/gradio/tree/main/.agents/skills/gradio -g -y

Use without installing

npx skills use gradio-app/gradio@gradio

指定 Agent (Claude Code)

npx skills add gradio-app/gradio --skill gradio -a claude-code -g -y

安装 repo 全部 skill

npx skills add gradio-app/gradio --all -g -y

预览 repo 内 skill

npx skills add gradio-app/gradio --list

SKILL.md

Frontmatter
{
    "name": "gradio",
    "description": "Build Gradio web UIs and demos in Python. Use when creating, modifying, debugging, or answering questions about Gradio and its capabilties, components, event listeners, or layouts."
}

Gradio

Gradio is a Python library for building interactive web UIs and ML demos. This skill covers the core API, patterns, and examples.

References

  • references/examples.md - Illustrative examples showcasing the core Gradio API.
  • references/api-signatures.md - API signatures of commonly used components.
  • references/event-listeners.md - API signatures of events supported by each component.

Guides

Detailed guides on specific topics (read these when relevant):

Core Patterns

Interface (high-level): wraps a function with input/output components.

import gradio as gr

def greet(name):
    return f"Hello {name}!"

gr.Interface(fn=greet, inputs="text", outputs="text").launch()

Blocks (low-level): flexible layout with explicit event wiring.

import gradio as gr

with gr.Blocks() as demo:
    name = gr.Textbox(label="Name")
    output = gr.Textbox(label="Greeting")
    btn = gr.Button("Greet")
    btn.click(fn=lambda n: f"Hello {n}!", inputs=name, outputs=output)

demo.launch()

ChatInterface: high-level wrapper for chatbot UIs.

import gradio as gr

def respond(message, history):
    return f"You said: {message}"

gr.ChatInterface(fn=respond).launch()

Workflow: builds a visual, node-based pipeline from Hugging Face Spaces, models, datasets, and Python functions. gr.Workflow is a standalone app, so do not create it inside a gr.Blocks context.

import gradio as gr

def clean(text: str) -> str:
    return text.strip().lower()

def tag(text: str) -> str:
    return f"[processed] {text}"

gr.Workflow(
    bind={"clean": clean, "tag": tag},
    edges=[("clean", "tag")],
).launch()

Custom HTML Components

If a task requires significant customization of an existing component or a component that doesn't exist in Gradio, you can create one with gr.HTML. It supports html_template (with ${} JS expressions and {{}} Handlebars syntax), css_template for scoped styles, and js_on_load for interactivity — where props.value updates the component value and trigger('event_name') fires Gradio events. For reuse, subclass gr.HTML and define api_info() for API/MCP support.

See the full guide as well as example in references/examples.md

Server Mode

Use gr.Server instead of gr.Blocks when the users requests any of the following:

  • Completely custom UI (your own HTML, React, Svelte, etc.) powered by Gradio's backend.
  • Full control of FastAPI server (custom GET/POST routes, middleware, dependency injection) alongside Gradio API endpoints

See the full guide and example in references/examples.md.

If the user's use case can be handled by Gradio's built-in components or customizable HTML components, prefer not to use gr.Server.

Version History

  • a535e77 Current 2026-08-20 18:50

Same Skill Collection

.agents/skills/frontend-unit-testing/SKILL.md
.agents/skills/gradio-themes/SKILL.md
.agents/skills/hf-gradio/SKILL.md

Metadata

Files
0
Version
2ae6f97
Hash
1782eab7
Indexed
2026-08-20 18:50

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-02 01:12
浙ICP备14020137号-1 $bản đồ khách truy cập$