Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import shutil
|
| 3 |
import logging
|
|
|
|
| 4 |
from fastapi import FastAPI, UploadFile, File, Form
|
| 5 |
from fastapi.responses import JSONResponse
|
| 6 |
from deepface import DeepFace
|
|
@@ -11,6 +12,19 @@ logger = logging.getLogger(__name__)
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Path database lokal (dipertahankan untuk kompatibilitas ke belakang)
|
| 15 |
DB_PATH = "/app/face_db"
|
| 16 |
if not os.path.exists(DB_PATH):
|
|
@@ -18,6 +32,8 @@ if not os.path.exists(DB_PATH):
|
|
| 18 |
|
| 19 |
@app.get("/")
|
| 20 |
async def root():
|
|
|
|
|
|
|
| 21 |
return {"status": "AI Face Recognition System is Running", "mode": "hybrid-stateless"}
|
| 22 |
|
| 23 |
@app.post("/api/represent")
|
|
@@ -47,6 +63,8 @@ async def represent_face(
|
|
| 47 |
enforce_detection=False
|
| 48 |
)
|
| 49 |
|
|
|
|
|
|
|
| 50 |
if len(representations) > 0:
|
| 51 |
embedding = representations[0]["embedding"]
|
| 52 |
return {"success": True, "embedding": embedding}
|
|
|
|
| 1 |
import os
|
| 2 |
import shutil
|
| 3 |
import logging
|
| 4 |
+
import psutil
|
| 5 |
from fastapi import FastAPI, UploadFile, File, Form
|
| 6 |
from fastapi.responses import JSONResponse
|
| 7 |
from deepface import DeepFace
|
|
|
|
| 12 |
|
| 13 |
app = FastAPI()
|
| 14 |
|
| 15 |
+
def log_ram_usage(context=""):
|
| 16 |
+
ram = psutil.virtual_memory()
|
| 17 |
+
process = psutil.Process(os.getpid())
|
| 18 |
+
process_ram = process.memory_info().rss / (1024 ** 3)
|
| 19 |
+
|
| 20 |
+
logger.info(
|
| 21 |
+
f"[RAM MONITOR] {context} | "
|
| 22 |
+
f"Total RAM: {ram.total / (1024 ** 3):.2f} GB | "
|
| 23 |
+
f"RAM Available: {ram.available / (1024 ** 3):.2f} GB | "
|
| 24 |
+
f"RAM Usage: {ram.percent}% | "
|
| 25 |
+
f"App RAM: {process_ram:.2f} GB"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
# Path database lokal (dipertahankan untuk kompatibilitas ke belakang)
|
| 29 |
DB_PATH = "/app/face_db"
|
| 30 |
if not os.path.exists(DB_PATH):
|
|
|
|
| 32 |
|
| 33 |
@app.get("/")
|
| 34 |
async def root():
|
| 35 |
+
log_ram_usage("Health Check")
|
| 36 |
+
|
| 37 |
return {"status": "AI Face Recognition System is Running", "mode": "hybrid-stateless"}
|
| 38 |
|
| 39 |
@app.post("/api/represent")
|
|
|
|
| 63 |
enforce_detection=False
|
| 64 |
)
|
| 65 |
|
| 66 |
+
log_ram_usage("After Face Representation")
|
| 67 |
+
|
| 68 |
if len(representations) > 0:
|
| 69 |
embedding = representations[0]["embedding"]
|
| 70 |
return {"success": True, "embedding": embedding}
|