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

相关内容

热门资讯

透视线上!wepoker怎么下... 透视线上!wepoker怎么下载游戏,aapoker怎么控制牌,讲义教程(的确有挂)-哔哩哔哩1、在...
八分钟辅助!xpoker辅助器... 八分钟辅助!xpoker辅助器(透视)一贯真的是有挂,wepoke教程(有挂规律)-哔哩哔哩1.xp...
透视玄学!wepoker正确养... 透视玄学!wepoker正确养号方法(透视)都是是有挂,大神讲解(有挂科技)-哔哩哔哩1、下载好we...
1分钟解迷!hhpoker透视... 1分钟解迷!hhpoker透视脚本(透视)切实有挂,可靠技巧(有挂方法)-哔哩哔哩1、金币登录送、破...
透视工具!aa poker辅助... 透视工具!aa poker辅助,hardrock透视工具,手段教程(有挂猫腻)-哔哩哔哩1、实时ha...
透视app!wepoker辅助... 透视app!wepoker辅助是真的吗(透视)好像有挂,技巧教程(有挂检测)-哔哩哔哩1、用户打开应...
第八分钟外挂!wpk有辅助吗(... 您好,wpk有辅助吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家...
透视辅助!hhpoker必备开... 透视辅助!hhpoker必备开挂,智星菠萝辅助,讲义教程(有挂详情)-哔哩哔哩hhpoker必备开挂...
透视辅助!wejoker透视方... 透视辅助!wejoker透视方法(透视)确实真的有挂,技巧教程(有挂透视)-哔哩哔哩1、用户打开应用...
4分钟分享!aapoker怎么... 4分钟分享!aapoker怎么选牌(透视)确实真的有挂,德州教程(有挂方式)-哔哩哔哩1、打开软件启...