Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI | |
| from app.rag import find_top_5_ayahs_qdrant | |
| from app.models.schemas import QuestionRequest, AnswerListResponse | |
| import psutil, os, asyncio | |
| app = FastAPI() | |
| def get_memory_usage_mb() -> float: | |
| """Return current memory usage in MB.""" | |
| process = psutil.Process(os.getpid()) | |
| return process.memory_info().rss / (1024 * 1024) | |
| async def log_memory_usage(): | |
| """Background task that prints memory usage every 10 seconds.""" | |
| async def monitor(): | |
| while True: | |
| mem = get_memory_usage_mb() | |
| print(f"💾 Memory usage: {mem:.2f} MB") | |
| await asyncio.sleep(10) | |
| asyncio.create_task(monitor()) | |
| def ask(payload: QuestionRequest): | |
| results = find_top_5_ayahs_qdrant(payload.question) | |
| return {"results": results} | |
| def read_root(): | |
| return {"message": "Hello, Mustafa! FastAPI is running 🚀"} | |
| def memory_endpoint(): | |
| """Check memory usage manually via /memory""" | |
| mem = get_memory_usage_mb() | |
| return {"memory_MB": round(mem, 2)} | |