New to Gradio? Start here: Getting Started
See the Release History
gradio.mount_gradio_app(app, blocks, path, ยทยทยท)
Example Usage
from fastapi import FastAPI
import gradio as gr
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="/gradio")
# Then run `uvicorn run:app` from the terminal and navigate to http://localhost:8000/gradio.
Initialization
Parameter | Description |
---|---|
app
fastapi.FastAPI required |
The parent FastAPI application. |
blocks
gradio.Blocks required |
The blocks object we want to mount to the parent app. |
path
str required |
The path at which the gradio application will be mounted. |
gradio_api_url
str | None default: None |
The full url at which the gradio app will run. This is only needed if deploying to Huggingface spaces of if the websocket endpoints of your deployed app are on a different network location than the gradio app. If deploying to spaces, set gradio_api_url to 'http://localhost:7860/' |
app_kwargs
dict[str, Any] | None default: None |
Additional keyword arguments to pass to the underlying FastAPI app as a dictionary of parameter keys and argument values. For example, `{"docs_url": "/docs"}` |