MossaabDev commited on
Commit
6fb30f2
·
verified ·
1 Parent(s): 25c723d

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +20 -36
app/main.py CHANGED
@@ -1,36 +1,20 @@
1
- from fastapi import FastAPI
2
- from app.rag import find_top_5_ayahs_qdrant
3
- from app.models.schemas import QuestionRequest, AnswerListResponse
4
- import psutil, os, asyncio
5
-
6
- app = FastAPI()
7
-
8
- def get_memory_usage_mb() -> float:
9
- """Return current memory usage in MB."""
10
- process = psutil.Process(os.getpid())
11
- return process.memory_info().rss / (1024 * 1024)
12
-
13
- @app.on_event("startup")
14
- async def log_memory_usage():
15
- """Background task that prints memory usage every 10 seconds."""
16
- async def monitor():
17
- while True:
18
- mem = get_memory_usage_mb()
19
- print(f"💾 Memory usage: {mem:.2f} MB")
20
- await asyncio.sleep(10)
21
- asyncio.create_task(monitor())
22
-
23
- @app.post("/ask/", response_model=AnswerListResponse)
24
- def ask(payload: QuestionRequest):
25
- results = find_top_5_ayahs_qdrant(payload.question)
26
- return {"results": results}
27
-
28
- @app.get("/")
29
- def read_root():
30
- return {"message": "Hello, Mustafa! FastAPI is running 🚀"}
31
-
32
- @app.get("/memory")
33
- def memory_endpoint():
34
- """Check memory usage manually via /memory"""
35
- mem = get_memory_usage_mb()
36
- return {"memory_MB": round(mem, 2)}
 
1
+ from fastapi import FastAPI
2
+ from app.rag import find_top_5_ayahs_qdrant
3
+ from app.models.schemas import QuestionRequest, AnswerListResponse
4
+ import psutil, os, asyncio
5
+
6
+ app = FastAPI()
7
+
8
+
9
+
10
+
11
+ @app.post("/ask/", response_model=AnswerListResponse)
12
+ def ask(payload: QuestionRequest):
13
+ results = find_top_5_ayahs_qdrant(payload.question)
14
+ return {"results": results}
15
+
16
+ @app.get("/")
17
+ def read_root():
18
+ return {"message": "Hello, Mustafa! FastAPI is running 🚀"}
19
+
20
+