File size: 954 Bytes
4787e22 |
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 |
import sys
import os
# add project root (E:\odisha_disaster_chatbot) to Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from backend.models import ChatRequest, ChatResponse # in backend/
from src.chatbot import RAGChatBot
app = FastAPI(title="Odisha Disaster Management Chatbot")
# ✅ Allow frontend to talk to backend
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Initialize chatbot once (not per request)
bot = RAGChatBot()
@app.post("/chat", response_model=ChatResponse)
def chat(request: ChatRequest):
answer = bot.chat(request.query)
return ChatResponse(answer=answer)
@app.get("/")
def root():
return {"message": "✅ Odisha Disaster Management Chatbot API is running"}
|