快速入门
import gradio as gr
def greet(name):
return "h1 " + name + "!"
gr.Interface(
fn=greet,
inputs="text",
outputs="text",
title="Greeting Interface",
description="This interface greets the user with the provided name."
).launch(share=True)
文件名为app.py,直接在终端运行python app.py。即会出现一个链接,打开链接,就会在浏览器界面出现内容。
![]()

但是使用这种方法,当需要更改代码时,更改后,需要将服务停掉,重新运行,很不方便。所以,第二种方法,使用debug模式运行。
方法:将接口赋值给demo(固定写法,debug模式必须在demo的命名空间下启动),然后用demo启动,最后在终端运行gradio app.py
import gradio as gr
def greet(name):
return "h1 " + name + "!"
demo = gr.Interface(
fn=greet,
inputs="text",
outputs="text",
title="Greeting Interface",
description="This interface greets the user with the provided name."
)
demo.launch(share=True)
![]()
Gradio 学习笔记:构建简单的 AI 交互界面
1. Gradio 简介
Gradio 是一个 Python 库,可以快速为机器学习模型创建友好的 Web 界面。它的特点是:
- 简单易用,几行代码即可创建界面
- 支持多种输入输出类型
- 可以快速分

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



