Subhakanta156's picture
Updated with Storage Monitor
762c589 verified
import os
import shutil
# ===== STORAGE MONITOR =====
def monitor_storage():
"""Monitor disk usage on startup"""
try:
total, used, free = shutil.disk_usage("/")
used_gb = used // (2**30)
free_gb = free // (2**30)
total_gb = total // (2**30)
print(f"\n{'='*60}")
print(f"💾 DISK USAGE:")
print(f" Total: {total_gb} GB")
print(f" Used: {used_gb} GB")
print(f" Free: {free_gb} GB")
print(f"{'='*60}")
# Check cache directories
cache_paths = {
"/app/.huggingface": "App Cache",
"/tmp/.huggingface": "Temp Cache",
"/app": "App Directory"
}
for path, name in cache_paths.items():
if os.path.exists(path):
try:
size = sum(
os.path.getsize(os.path.join(root, file))
for root, _, files in os.walk(path)
for file in files
)
size_gb = size / (2**30)
print(f"📦 {name} ({path}): {size_gb:.2f} GB")
except Exception as e:
print(f"⚠️ Could not measure {name}: {e}")
print(f"{'='*60}\n")
except Exception as e:
print(f"⚠️ Storage monitoring failed: {e}")
# Run storage check
monitor_storage()
# ===== END STORAGE MONITOR =====
import sys
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
# add project root to Python path
BASE_DIR = Path(__file__).resolve().parent
sys.path.append(str(BASE_DIR))
# import backend modules
from backend.models import ChatRequest, ChatResponse
from src.chatbot import RAGChatBot
# Initialize chatbot
bot = RAGChatBot()
# Log FAISS index size safely
try:
size = getattr(bot, "index_size", None)
if size is None and hasattr(bot, "index"):
# if RAGChatBot has .index (FAISS object) instead
size = len(bot.index) if hasattr(bot.index, "__len__") else "unknown"
print(f"✅ FAISS index size: {size}")
except Exception as e:
print(f"⚠️ Could not determine FAISS index size: {e}")
# Create FastAPI app
app = FastAPI(title="Odisha Disaster Chatbot")
# Enable CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Serve frontend static files
frontend_dir = BASE_DIR / "frontend"
app.mount("/static", StaticFiles(directory=str(frontend_dir)), name="static")
# Serve index.html at root
@app.get("/")
def read_index():
return FileResponse(frontend_dir / "index.html")
# Backend chat API
@app.post("/api/chat", response_model=ChatResponse)
def chat(request: ChatRequest):
answer = bot.chat(request.query)
return ChatResponse(answer=answer)
# Optional health check
@app.get("/health")
def health():
return {"status": "ok"}