File size: 1,025 Bytes
a2ff264 3e4d292 a2ff264 3e4d292 a2ff264 3e4d292 a2ff264 002bb9e a2ff264 002bb9e a2ff264 3e4d292 a2ff264 002bb9e 3e4d292 002bb9e 6910040 |
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 |
from fastapi import FastAPI
from backend.api import items, pdfreader, textreader
from fastapi.middleware.cors import CORSMiddleware
import gradio as gr
app = FastAPI(title="Multi-layered FastAPI Example")
# === CORS Middleware ===
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# === Include API routers ===
app.include_router(items.router)
app.include_router(pdfreader.router)
app.include_router(textreader.router)
# === Gradio Function ===
def gradio_func(text):
return f"Gradio received: {text}"
gradio_app = gr.Interface(fn=gradio_func, inputs="text", outputs="text")
# === Mount Gradio at /gradio ===
from gradio.routes import App as GradioApp
gradio_app.launch(inline=True, prevent_thread_lock=True)
app.mount("/gradio", GradioApp.create_app(gradio_app))
# === Uvicorn Entry ===
if __name__ == "__main__":
import uvicorn
uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=True)
|