Spaces:
Runtime error
Runtime error
Download backend/api.py from Subhakanta156/Odisha-Disaster-Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 954 Bytes
-
https://huggingface.co/spaces/Subhakanta156/Odisha-Disaster-Chatbot/resolve/main/backend/api.py
- Command line
-
hf download hf://spaces/Subhakanta156/Odisha-Disaster-Chatbot/backend/api.py
-
curl -L -o api.py https://huggingface.co/spaces/Subhakanta156/Odisha-Disaster-Chatbot/resolve/main/backend/api.py
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() | |
| def chat(request: ChatRequest): | |
| answer = bot.chat(request.query) | |
| return ChatResponse(answer=answer) | |
| def root(): | |
| return {"message": "✅ Odisha Disaster Management Chatbot API is running"} | |