Closed snps-ravinu closed 1 month ago
Hi @snps-ravinu ! This is expected. Gradio can't serve arbitrary files from your computer/server for security reasons. To serve a file from outside the app directory, use the allowed_paths
argument of mount_gradio_app
.
The following works for me. Note that I am running this from the same directory as the app.py
. If I was running it from a different directory, I would have to use the full path to the static dir in the markdown component.
import gradio as gr
from fastapi import FastAPI
with gr.Blocks() as demo:
gr.Markdown("<img src='/file=static/cheetah.jpg' width='300px'>")
app = FastAPI()
app = gr.mount_gradio_app(app=app, blocks=demo, path="/",
allowed_paths=["<full-path-to-static-dir>/static"])
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, port=7860)
Thanks @freddyaboulton, to update on the issue, I was using allowed paths, but the issue was with the path I was giving in the img src, my ui mount path was "/ui", so I had to insert "/ui" to the src path and that resolved the issue
Describe the bug
I have an image in my "assests" folder, while using mount_gradio_app, the gradio.Blocks object contains "img" in html like this,,
, but this is not rendering the image, I tried to give relative path as well. Whenever image is in a different directory which is outside the app.py(where mounting is done), I am seeing this issue.
Have you searched existing issues? 🔎
Reproduction
Screenshot
No response
Logs
No response
System Info
Severity
I can work around it