Gradio App 就是给 AI 算法工程师训练的模型赋予分享给大众的能力。
从技术侧拆分,由三个部分组成:
前端页面 + 后端接口 + AI算法模型推理
Gradio 做了一件事情,就是将这三个部分封装到一个 python 接口里,用户通过实现其封装的接口,将自己训练的算法模型以 web 服务的形式展现给大众使用。
1. 一个简单的 gradio 程序
该实例源自官网 Gradio
import gradio as gr
def sketch_recognition(img):
pass# Implement your sketch recognition model here...
gr.Interface(fn=sketch_recognition, inputs="sketchpad", outputs="label").launch()
用户在交互界面上用鼠标画一幅简笔画,后端给出其分类。
可以看到 gr.Interface().lanuch() 就是将前端页面,后端服务以及 AI 算法模型三者结合到一个接口里,极大的降低了算法模型落地的难度,使得 AI 算法工程师在不具备工程能力的情况下,也能拿快速部署前后端并提供服务。
2. 安装
pip install gradio
3. Hello World
开始学起都是从输出"hello world"开始,这里也不例外。
import gradio as gr
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()
上面的代码运行后,在http// localhost:7860
上弹出浏览器:
左边输入对应的name,右边有基于程序的输出:
参考文献
Gradio app 基于 Kubernetes 部署实战 - 掘金
Gradio实现算法可视化_uncle_ll的博客-CSDN博客