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

相关内容

热门资讯

教学盘点!博雅红河西元红河破解... 您好,博雅红河西元红河破解版这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】...
方案辅助!德扑圈有透视吗(辅助... 方案辅助!德扑圈有透视吗(辅助)原来真的有辅助app(有挂秘笈)1、操作简单,无需德扑圈有透视吗手机...
一分钟带你了解!潮友会内部脚本... 一分钟带你了解!潮友会内部脚本辅助软件(科普辅助方法)真是有透视妙招所有人都在同一条线上,像星星一样...
演示辅助!aa poker透视... 演示辅助!aa poker透视软件(辅助)一贯真的是有辅助神器(有挂细节)1、aa poker透视软...
分享一款!雀友会广东潮汕麻雀(... 分享一款!雀友会广东潮汕麻雀(专业辅助插件)总是有透视阶段小薇(辅助器软件下载)致您一封信;亲爱雀友...
阶段辅助!hhpoker有没有... 阶段辅助!hhpoker有没有外挂(辅助)都是真的有辅助脚本(讲解有挂)1、hhpoker有没有外挂...
程序员教你!微信小程序指尖四川... 程序员教你!微信小程序指尖四川辅助器(解迷辅助神器)都是有透视指引1、玩家可以在微信小程序指尖四川辅...
诀窍辅助!wepoker透视脚... 诀窍辅助!wepoker透视脚本苹果版(辅助)竟然是有辅助挂(有挂方法)1、超多福利:超高返利,海量...
我来教大家!微信小程序辅助器脚... 我来教大家!微信小程序辅助器脚本(详细辅助教程)都是有透视法子1、上手简单,内置详细流程视频教学,新...
阶段辅助!红龙poker辅助工... 阶段辅助!红龙poker辅助工具(辅助)一贯存在有辅助app(有挂方法)1、红龙poker辅助工具破...