|
|
import os |
|
|
import shutil |
|
|
|
|
|
|
|
|
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}") |
|
|
|
|
|
|
|
|
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}") |
|
|
|
|
|
|
|
|
monitor_storage() |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent |
|
|
sys.path.append(str(BASE_DIR)) |
|
|
|
|
|
|
|
|
from backend.models import ChatRequest, ChatResponse |
|
|
from src.chatbot import RAGChatBot |
|
|
|
|
|
|
|
|
bot = RAGChatBot() |
|
|
|
|
|
|
|
|
try: |
|
|
size = getattr(bot, "index_size", None) |
|
|
if size is None and hasattr(bot, "index"): |
|
|
|
|
|
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}") |
|
|
|
|
|
|
|
|
app = FastAPI(title="Odisha Disaster Chatbot") |
|
|
|
|
|
|
|
|
app.add_middleware( |
|
|
CORSMiddleware, |
|
|
allow_origins=["*"], |
|
|
allow_credentials=True, |
|
|
allow_methods=["*"], |
|
|
allow_headers=["*"], |
|
|
) |
|
|
|
|
|
|
|
|
frontend_dir = BASE_DIR / "frontend" |
|
|
app.mount("/static", StaticFiles(directory=str(frontend_dir)), name="static") |
|
|
|
|
|
|
|
|
@app.get("/") |
|
|
def read_index(): |
|
|
return FileResponse(frontend_dir / "index.html") |
|
|
|
|
|
|
|
|
@app.post("/api/chat", response_model=ChatResponse) |
|
|
def chat(request: ChatRequest): |
|
|
answer = bot.chat(request.query) |
|
|
return ChatResponse(answer=answer) |
|
|
|
|
|
|
|
|
@app.get("/health") |
|
|
def health(): |
|
|
return {"status": "ok"} |