gradio: UI not displaying properly because path to theme.css is not using the provided root_path
I have tried all the solutions listed in this issue as well as #3798, #3662, #3482, #3472 and https://stackoverflow.com/questions/61641514/css-not-recognized-when-served-with-fastapi.
Solutions that I have tried include:
- Mounting the subapp to my FastAPI app
- Providing a root_path to the FastAPI declaration
- Providing a root_path to the mount_gradio_app() method
- Using both the mount function from FastAPI in conjunction with the mount_gradio_app()
- Downgrading and upgrading gradio to 3.50.1, 4.19.0, 4.20.0, 4.21.0, 4.25.0
My issue is the same as stated in the issue title of #3472. When running behind a proxy and load balancer, the gradio app requests the theme.css at the root of the url and not after the url+prefix. I have tried providing the root_path at the app.mount_gradio_app(root_path=) level and at the app=FastAPI(rooth_path=) level.
The gradio app runs at the provided root_path but the theme.css file is requested at the url without the root_path:
I have tried a few different releases from gradio and the gradio python client and have the problem persisting.
This is a sample version of the two solutions I have tried in my code that don’t provide the right url to get the theme.css. Both ways work to have the gradio app running with the prefix at https//:abc.com/app/gradio but the theme is requested at https//:abc.com/gradio and fails.
Try 1:
import gradio as gr
import uvicorn
app = FastAPI(root_path="/app")
@app.get('/')
def hello():
return {"message":"hello"}
g_app = gr.Interface(
lambda x: f"Hello {x}",
"textbox",
"textbox",
)
app = gr.mount_gradio_app(app, g_app, path="/gradio")
uvicorn.run(app,host="0.0.0.0",port=8080)
Try 2:
from fastapi import FastAPI
import gradio as gr
import uvicorn
app = FastAPI()
@app.get('/')
def hello():
return {"message":"hello"}
g_app = gr.Interface(
lambda x: f"Hello {x}",
"textbox",
"textbox",
)
app = gr.mount_gradio_app(app, g_app, path="/gradio",root_path="/app")
uvicorn.run(app,host="0.0.0.0",port=8080)
Thx for the help.
_Originally posted by @PaulClas in https://github.com/gradio-app/gradio/issues/3472#issuecomment-2038081429_
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 46 (21 by maintainers)
I had the same problem with version 4.26.0, and going back to version 4.20.0 helped me solve the problem. But I hope this problem can be completely resolved in the next versions.
Im having the same issue. Using a gradio app mounted to
/gradiowithmount_gradio_app(). Gradio app is an AWS Lambda Function behind Cloudfront cdn (proxy). When accessing the function url directly (without cloudfront) things work fine. When accessing through the cdn, the following paths (that Ive found so far) are being routed to the root of the application, rather than on the mounted path of/gradio:/theme.css/assets/index-CKyT5UbA.css/queue/join/queue/dataThere must be a header or a cookie that isn’t being forwarded causing this issue… Who knows where/how the /theme.css routes are created?
I am using the fix found in this issue response. Works for me right now… https://github.com/gradio-app/gradio/issues/8073#issuecomment-2139100287
I’m also using FastAPI and mount_gradio_app, only setting the path. There’s a nginx reverse proxy in front of the app.
I also see this path value is missing for theme.css.
I’m seeing the same missing
theme.cssbehavior with v4.25.0. Rolling back to v4.20.0 seems to provide a temporary fix.It’s very hard for us to debug this without a reproduction. I’ve checked and the theme.css does use the config.root value, so I’m guessing the problem is either in the js client or the backend.
Hmm I thought this was fixed. Let me look into this