Is it possible to mount multiple Gradio apps with FastAPI? I’d like to have two endpoints: localhost:8000 and localhost:8000/debug. The /debug endpoint would ultimately be a bit more complex and log more data. I thought I’d be able to do something like this:
from fastapi import FastAPI
from functools import partial
import gradio as gr
app = FastAPI()
sub_app = FastAPI()
app.mount('/debug', sub_app)
def out(text, n):
return text + '!'*n
def make_simple_gr_app(n):
func = partial(out, n=n)
with gr.Blocks() as dbg:
textbox = gr.Textbox(max_lines=1, label='Enter text')
submit_btn = gr.Button('Submit')
submit_btn.click(func, inputs=textbox, outputs=textbox)
return dbg
sub_app = gr.mount_gradio_app(sub_app, make_simple_gr_app(1), '/')
app = gr.mount_gradio_app(app, make_simple_gr_app(5), '/')
Now when I go to localhost:8000
it works, but when accessing localhost:8000/debug
the logs show "GET /debug HTTP/1.1" 404 Not Found
which I don’t understand since I would think the app.mount(..)
would take care of that part.
What am I missing?