Spaces:
Runtime error
Runtime error
File size: 1,071 Bytes
91e9c16 |
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 |
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from backend_api import create_api_app
from chat_ui import create_chat_interface
try:
from fastapi_gradio import mount_gradio_app
except ImportError:
# fallback if helper lib not installed
from gradio.routes import mount_gradio_app
app = create_api_app()
# Allow frontend apps to talk to backend
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Mount Gradio Chat UI at /chat
gradio_chat_app = create_chat_interface()
mount_gradio_app(app, gradio_chat_app, path="/chat")
@app.get("/")
def root():
return HTMLResponse("""
<h2>Omniscient Framework API</h2>
<p>Available endpoints:</p>
<ul>
<li><a href="/docs">API Documentation (Swagger)</a></li>
<li><a href="/chat">Chatbot UI (Gradio)</a></li>
</ul>
""")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7860)
|