NexusInstruments commited on
Commit
91e9c16
·
verified ·
1 Parent(s): a7d33e4

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +44 -0
main.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import HTMLResponse
3
+ from fastapi.middleware.cors import CORSMiddleware
4
+ import uvicorn
5
+
6
+ from backend_api import create_api_app
7
+ from chat_ui import create_chat_interface
8
+
9
+ try:
10
+ from fastapi_gradio import mount_gradio_app
11
+ except ImportError:
12
+ # fallback if helper lib not installed
13
+ from gradio.routes import mount_gradio_app
14
+
15
+ app = create_api_app()
16
+
17
+ # Allow frontend apps to talk to backend
18
+ app.add_middleware(
19
+ CORSMiddleware,
20
+ allow_origins=["*"],
21
+ allow_credentials=True,
22
+ allow_methods=["*"],
23
+ allow_headers=["*"],
24
+ )
25
+
26
+ # Mount Gradio Chat UI at /chat
27
+ gradio_chat_app = create_chat_interface()
28
+ mount_gradio_app(app, gradio_chat_app, path="/chat")
29
+
30
+
31
+ @app.get("/")
32
+ def root():
33
+ return HTMLResponse("""
34
+ <h2>Omniscient Framework API</h2>
35
+ <p>Available endpoints:</p>
36
+ <ul>
37
+ <li><a href="/docs">API Documentation (Swagger)</a></li>
38
+ <li><a href="/chat">Chatbot UI (Gradio)</a></li>
39
+ </ul>
40
+ """)
41
+
42
+
43
+ if __name__ == "__main__":
44
+ uvicorn.run(app, host="0.0.0.0", port=7860)