Spaces:
Runtime error
Runtime error
| 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") | |
| 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) | |