-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (47 loc) · 1.5 KB
/
main.py
File metadata and controls
58 lines (47 loc) · 1.5 KB
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
52
53
54
55
56
57
58
# loading all required modules
from dotenv import load_dotenv
import os
load_dotenv()
import uvicorn
import asyncio
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from backend.api.v1.routes import system_routes
from backend.api.v1.routes import login_routes
from backend.api.v1.routes import chat_routes
from backend.api.v1.routes import pdf_routes
from backend.api.v1.utils.utils import *
# initialize the app
app = FastAPI(
title="Document-QA-ChatBot-System-APIs",
description="Backend APIs for document-based QA chatbot system",
version="1.0.0",
)
# Configure CORS (for frontend UI)
origins = [
"http://127.0.0.1:8080",
"http://localhost:8080",
"http://frontend:8080",
"http://frontend:8080"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include API Routes
app.include_router(system_routes.router, prefix="/api/v1/system", tags=["System"])
app.include_router(login_routes.router, prefix="/api/v1/login", tags=["Login"])
app.include_router(chat_routes.router, prefix="/api/v1/chat", tags=["Chat"])
app.include_router(pdf_routes.router, prefix="/api/v1/pdf", tags=["PDF"])
# app startup events
@app.on_event("startup")
async def startup_event():
print(f"Application startup...\n")
# app shutdown events
@app.on_event("shutdown")
async def shutdown_event():
print(f"Application shutdown...\n")