用途:Gradio 是 Python 库,用于构建交互式 Web UI 和机器学习演示。本技能覆盖其核心 API、模式与示例,适合在创建或编辑 Gradio 应用、组件、事件监听器、布局或聊天机器人时使用。
主要能力与核心模式:
- Interface(高层):用输入/输出组件包装一个函数。示例: import gradio as gr def greet(name): return f"Hello {name}!" gr.Interface(fn=greet, inputs="text", outputs="text").launch()
- Blocks(底层):灵活布局并显式连接事件。示例: 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:聊天机器人 UI 的高层封装。示例: import gradio as gr def respond(message, history): return f"You said: {message}" gr.ChatInterface(fn=respond).launch()
组件:资料列出 Textbox、Number、Slider、Checkbox、Dropdown、Radio、Image、Audio、Video、File、Chatbot、Button、Markdown、HTML 等组件的签名与用途,例如 Textbox 创建文本输入/输出区域,Image 支持上传或显示图像,Chatbot 显示用户消息与回复。
指南主题:快速开始、Interface 类、Blocks 与事件监听器、控制布局、更多 Blocks 功能、自定义 CSS 与 JS、流式输出、流式输入、分享应用、自定义 HTML 组件、Python 客户端入门、JS 客户端入门。
使用方式:通过 pip 安装 Gradio 后,用 Python 编写应用并调用 .launch() 启动;可参考上述指南与组件签名。
限制:资料未提供具体安装命令、收费、价格、平台支持或效果说明,这些事实暂未提供。