230902-部署Gradio到已有FastAPI及服务器中
创始人
2025-01-17 04:37:11
0

在这里插入图片描述

1. 官方例子

  • run.py
from fastapi import FastAPI import gradio as gr  CUSTOM_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 gr   def greet(text: str) -> str:     return text   demo = 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 gr  from gradio_ui import demo  app = FastAPI()  @app.get('/') async def root():     return 'Gradio app is running at /gradio', 200  app = 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

相关内容

热门资讯

九分钟推荐!德州ai辅助有用,... 九分钟推荐!德州ai辅助有用,(We辅poker助)好像真的有挂,详细教程(有挂神器)-哔哩哔哩1、...
7分钟黑科技!微扑克发牌机制(... 7分钟黑科技!微扑克发牌机制(透明黑科技)外挂透明挂辅助APP(2022已更新)(哔哩哔哩)1、完成...
九分钟体悟!线上德州辅助工具有... 九分钟体悟!线上德州辅助工具有哪些(微扑克ai辅助器苹果版)其实真的有挂(2023已更新)(哔哩哔哩...
玩家攻略推荐(wePokE)好... 玩家攻略推荐(wePokE)好像真的有挂(辅助挂)外挂透明挂辅助神器(2023已更新)(哔哩哔哩)1...
五分钟了解!wpk辅助软件,(... 五分钟了解!wpk辅助软件,(AAPoker)总是真的有挂,第三方教程(有挂插件)-小红书1、wpk...
2分钟黑科技!wpk俱乐部盈利... 2分钟黑科技!wpk俱乐部盈利模式(软件透明挂)外挂透明挂辅助软件(2025已更新)(哔哩哔哩)1、...
5分钟体悟!aapoker脚本... 5分钟体悟!aapoker脚本透明(微扑克有辅助挂)都是真的有挂(2025已更新)(哔哩哔哩);1、...
分享认知(GG扑克)都是真的有... 分享认知(GG扑克)都是真的有挂(透视)外挂透明挂辅助器(2025已更新)(哔哩哔哩)1、分享认知(...
2分钟发现!wepoke辅助软... 2分钟发现!wepoke辅助软件下载,(线上德州)就是真的有挂,实用技巧(有挂脚本)-百度知乎暗藏猫...
6分钟黑科技!wpk有透视辅助... 6分钟黑科技!wpk有透视辅助(透明黑科技)外挂透明挂辅助器安装(2025已更新)(哔哩哔哩)1、超...