gradio
gradio copied to clipboard
Support Static Page + Gradio app boilerplate deployment
Problem
Currently, there is no straightforward method to integrate a custom frontend experience that connects to a Gradio API backend via @gradio/client
. More specifically, there's no easy way to serve static content alongside the Gradio App.
Here is the current workaround:
import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
import gradio as gr
from pathlib import Path
def predict(text):
return text
with gr.Blocks() as block:
text_in = gr.Textbox()
text_out = gr.Textbox()
btn = gr.Button("Predict")
btn.click(predict, inputs=[text_in], outputs=[text_out], api_name="predict")
block.queue()
app = FastAPI()
static_dir = Path("./static")
app = gr.mount_gradio_app(app, block, path="/gradio")
app.mount("/", StaticFiles(directory=static_dir, html=True), name="static")
if __name__ == "__main__":
uvicorn.run("app:app", host="0.0.0.0", port=7860)
Ideas
To simplify this process, could we possibly offer an API?
import gradio as gr
def predict(text):
return text
with gr.Blocks() as block:
text_in = gr.Textbox()
text_out = gr.Textbox()
btn = gr.Button("Predict")
btn.click(predict, inputs=[text_in], outputs=[text_out], api_name="predict")
block.queue()
block.launch(serve_static_html="../static", gradio_path="/gradio")
Alternatively, we could integrate this feature via gradio deploy
.
cc @pngwn