Spaces:
Build error
Build error
import gradio as gr | |
from fastapi import FastAPI | |
from fastapi.staticfiles import StaticFiles | |
from fastapi.middleware.cors import CORSMiddleware | |
app = FastAPI() | |
blocks = gr.Blocks().queue() | |
with blocks as demo: | |
with gr.Row(): | |
with gr.Column(scale=3, min_width=270): | |
text_input = gr.Textbox( | |
label="Input", placeholder="input your text here", lines=4 | |
) | |
with gr.Column(scale=2, min_width=150): | |
text_output = gr.Textbox( | |
label="Output", lines=4 | |
) | |
run_button = gr.Button("Run") | |
run_button.click( | |
fn=lambda x: x, | |
inputs=[text_input], | |
outputs=[text_output], | |
) | |
blocks.config['dev_mode'] = False | |
app = gr.mount_gradio_app(app, blocks, "/gradio", | |
gradio_api_url="http://0.0.0.0:8000/gradio/") | |
async def your_api(): | |
return {"message": "Hello World"} | |
app.mount("/", StaticFiles(directory="static", html=True), name="static") | |
origins = ["*"] | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=origins, | |
allow_credentials=True, | |
allow_methods=["*"], | |
allow_headers=["*"], | |
) | |