具体详情看gradio docsGradio Interface Docs
gradio_web.py文件
主要用两个函数,interface生成接口,client调用接口
import gradio as gr
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(
fn=greet,
inputs=gr.Textbox(lines=3, placeholder="Name Here...",label="my input"),
outputs="text",
)
demo.launch(debug=True, share=True, server_name="0.0.0.0", server_port=7861)
fn是函数,函数的输入值有一个,str
inputs要对应函数的输入值
output要对应函数的输出值
launch函数生成接口和端口,其中share表示公开分享,运行结果:
有本地url和公开url。公开72h
client_demo.py文件
from gradio_client import Client
client = Client("https://153b564cd4e5053cfa.gradio.live")
print(client.predict("22"))
也可以不公开,用本地url。predict里的输入要和函数的输入对齐,按顺序输入就行