Subhakanta
Initial commit without data folder
4787e22
raw
history blame contribute delete
954 Bytes
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"}