gradio icon indicating copy to clipboard operation
gradio copied to clipboard

Mount a gradio.Blocks in a FastAPI results in websocket not found

Open miguelwon opened this issue 10 months ago • 2 comments

Describe the bug

The [example](https://www.gradio.app/docs/mount_gradio_app) on how to mount blocks to a FastAPI app, outputs the following error:

(ml-pt-3) miguelwon@Miguels-MBP demo % uvicorn teste:app
INFO:     Started server process [7495]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     127.0.0.1:61936 - "GET /ws/socket.io/?EIO=4&transport=polling&t=Ow5RbvQ HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:61963 - "GET /ws/socket.io/?EIO=4&transport=polling&t=Ow5RdN8 HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:61963 - "GET /ws/socket.io/?EIO=4&transport=polling&t=Ow5RdNX HTTP/1.1" 404 Not Found

Have you searched existing issues? 🔎

  • [X] I have searched and found no existing issues

Reproduction

import gradio as gr

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.

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Darwin
gradio version: 4.24.0
gradio_client version: 0.14.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.2.0
fastapi: 0.108.0
ffmpy: 0.3.1
gradio-client==0.14.0 is not installed.
httpx: 0.25.1
huggingface-hub: 0.20.3
importlib-resources: 6.1.1
jinja2: 3.1.2
markupsafe: 2.1.3
matplotlib: 3.8.0
numpy: 1.26.3
orjson: 3.9.10
packaging: 23.2
pandas: 1.5.3
pillow: 10.0.1
pydantic: 2.4.2
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.2.2
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.9.0
typing-extensions: 4.9.0
uvicorn: 0.29.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2023.6.0
httpx: 0.25.1
huggingface-hub: 0.20.3
packaging: 23.2
typing-extensions: 4.9.0
websockets: 11.0.3

Severity

I can work around it

miguelwon avatar Mar 28 '24 14:03 miguelwon

Hi @miguelwon ! I can't repro with those versions of gradio and fastapi. I'm not sure where that websocket connection is coming from, gradio does not use websockets anymore. Even with that error, I think the app should be functioning correctly though.

image

freddyaboulton avatar Mar 28 '24 14:03 freddyaboulton

Just installed a fresh new environment with gradio, fastapi and uvicorn, and still getting the same error. Perhaps is a uvicorn issue. If I find the solution I'll report it here. Thanks, anyway!

miguelwon avatar Mar 28 '24 15:03 miguelwon

Strange, will go ahead and close this issue.

abidlabs avatar Apr 05 '24 19:04 abidlabs