230902-部署Gradio到已有FastAPI及服务器中
短信预约 -IT技能 免费直播动态提醒
1. 官方例子
run.py
from fastapi import FastAPIimport 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 FastAPIimport 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. 文件对象,不要带py3. 需要在同一个根目录下
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
来源地址:https://blog.csdn.net/qq_33039859/article/details/132639461
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341