| 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() | |
| def chat(request: ChatRequest): | |
| answer = bot.chat(request.query) | |
| return ChatResponse(answer=answer) | |
| def root(): | |
| return {"message": "✅ Odisha Disaster Management Chatbot API is running"} | |