当前位置: 首页 > news >正文

230902-部署Gradio到已有FastAPI及服务器中

在这里插入图片描述

1. 官方例子

  • run.py
from fastapi import FastAPI
import gradio as grCUSTOM_PATH = "/gradio"app = FastAPI()@app.get("/")
def read_main():return {"message": "This is your main app"}io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
app = gr.mount_gradio_app(app, io, path=CUSTOM_PATH)# Run this from the terminal as you would normally start a FastAPI app: `uvicorn run:app`
# and navigate to http://localhost:8000/gradio in your browser.

运行方式:uvicorn run:app

2. 油管例子

  • gradio_ui.py
import gradio as grdef greet(text: str) -> str:return textdemo = gr.Interface(fn=greet,inputs=gr.components.Textbox(label='Input'),outputs=gr.components.Textbox(label='Output'),allow_flagging='never'
)
  • run.py
from fastapi import FastAPI
import gradio as grfrom gradio_ui import demoapp = FastAPI()@app.get('/')
async def root():return 'Gradio app is running at /gradio', 200app = gr.mount_gradio_app(app, demo, path='/gradio')
  • 运行方式
uvicorn run:app --host 0.0.0.0 --port 5000
  • 注意事项
1. 在命令行中的格式是<文件对象:挂载对象>
2. 文件对象,不要带py
3. 需要在同一个根目录下

3. 视频演示

230920-部署Gradio到已有FastAPI及服务器中

4. 参考文献

  • mounting-within-another-fast-api-app
  • RajKKapadia/YouTube-Gradio-Deploy-Demo
  • How to deploy Gradio application on Server | Render | Gradio | Python - YouTube
http://www.lryc.cn/news/152157.html

相关文章:

  • Ubuntu本地快速搭建web小游戏网站,公网用户远程访问【内网穿透】
  • 【LeetCode-中等题】199. 二叉树的右视图
  • 【调试经验】Ubuntu22.04 安装和配置MySQL 8.0.34
  • Android 使用OpenCV实现实时人脸识别,并绘制到SurfaceView上
  • 【自然语言处理】关系抽取 —— GDPNet 讲解
  • 【小沐学NLP】Python使用NLTK库的入门教程
  • Angular安全专辑之三 —— 授权绕过,利用漏洞控制管理员账户
  • 使用Sumo以及traci实现交叉口信号灯自适应控制
  • 自定义类型:结构体、枚举、联合
  • 如何使用ZIP方式安装MySQL:简单、快速、高效的安装方法
  • python嵌套循环
  • 一文速学-让神经网络不再神秘,一天速学神经网络基础(五)-最优化
  • 【AWS实验】 配置中转网关及对等连接
  • 47、springboot 的 国际化消息支持--就是根据浏览器选择的语言,项目上的一些提示信息根据语言的选择进行对应的显示
  • 重要变更 | Hugging Face Hub 的 Git 操作不再支持使用密码验证
  • 为什么删除Windows 11上的Bloatware可以帮助加快你的电脑速度
  • PCL点云处理之计算两条直线间最短连线的端点 (二百零三)
  • 纵行科技与山鹰绿能达成合作,提供物联网资产管理数据服务
  • 【2511. 最多可以摧毁的敌人城堡数目】
  • stm32f1xx单片机拦截中断源代码
  • C++(21):特殊工具与技术
  • go读取yaml,json,ini等配置文件
  • 一、安装GoLang环境和开发工具
  • 条款40:对并发使用std::atomic,对特种内存使用valatile
  • Navicat使用HTTP通道服务器进行连接mysql数据库(超简单三分钟完成),centos安装nginx和php,docker安装nginx+php合并版
  • 图:有向无环图(DAG)
  • Python入门教程 - 基本语法 (一)
  • 使用PAM保障开发运营安全
  • 《Go 语言第一课》课程学习笔记(十二)
  • 【深入浅出C#】章节10: 最佳实践和性能优化:编码规范和代码风格