Spaces:
Build error
Build error
File size: 1,181 Bytes
9abe28f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
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/")
@ app.get('/api/your_api')
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=["*"],
)
|