Spaces:
Sleeping
Sleeping
Update core/config.py
Browse files- core/config.py +23 -74
core/config.py
CHANGED
|
@@ -1,76 +1,25 @@
|
|
| 1 |
import os
|
| 2 |
-
import gc
|
| 3 |
-
import asyncio
|
| 4 |
-
import pandas as pd
|
| 5 |
-
from contextlib import asynccontextmanager
|
| 6 |
-
from fastapi import FastAPI
|
| 7 |
-
from fastapi.responses import HTMLResponse
|
| 8 |
-
from fastapi.staticfiles import StaticFiles
|
| 9 |
-
from fastapi.templating import Jinja2Templates
|
| 10 |
-
from starlette.requests import Request
|
| 11 |
-
import uvicorn
|
| 12 |
|
| 13 |
-
# -
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
if os.path.exists(LOG_FILE):
|
| 37 |
-
try:
|
| 38 |
-
df = pd.read_csv(LOG_FILE)
|
| 39 |
-
for _, row in df.iterrows():
|
| 40 |
-
attendance_memory.insert(0, {"name": row['Name'], "time": row['Time']})
|
| 41 |
-
print(f"✅ Loaded {len(attendance_memory)} records.")
|
| 42 |
-
except: pass
|
| 43 |
-
else:
|
| 44 |
-
with open(LOG_FILE, "w") as f: f.write("Name,Time\n")
|
| 45 |
-
|
| 46 |
-
yield
|
| 47 |
-
# --- SHUTDOWN PHASE ---
|
| 48 |
-
pass
|
| 49 |
-
|
| 50 |
-
# --- AI Warmup Sequence ---
|
| 51 |
-
print("🚀 Booting Dynamic Consensus AI Core...")
|
| 52 |
-
try:
|
| 53 |
-
for model in MODELS:
|
| 54 |
-
DeepFace.build_model(model)
|
| 55 |
-
DeepFace.build_model("RetinaFace")
|
| 56 |
-
print(f"🧠 {', '.join(MODELS)} Networks Loaded.")
|
| 57 |
-
gc.collect()
|
| 58 |
-
except Exception as e:
|
| 59 |
-
print(f"⚠️ AI Boot Error: {e}")
|
| 60 |
-
|
| 61 |
-
# --- FastAPI Application ---
|
| 62 |
-
app = FastAPI(title="Enterprise Attendance API", version="5.0.0", lifespan=lifespan)
|
| 63 |
-
|
| 64 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 65 |
-
templates = Jinja2Templates(directory="templates")
|
| 66 |
-
|
| 67 |
-
# Register the websocket route
|
| 68 |
-
app.add_api_websocket_route("/ws", websocket_endpoint)
|
| 69 |
-
|
| 70 |
-
@app.get("/", response_class=HTMLResponse)
|
| 71 |
-
async def read_root(request: Request):
|
| 72 |
-
"""Serves the main application dashboard."""
|
| 73 |
-
return templates.TemplateResponse("index.html", {"request": request})
|
| 74 |
-
|
| 75 |
-
if __name__ == "__main__":
|
| 76 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# AI Configuration - Smart Consensus Engine
|
| 4 |
+
DETECTOR = "retinaface"
|
| 5 |
+
MODELS = ["ArcFace", "Facenet512"]
|
| 6 |
+
THRESHOLDS = {
|
| 7 |
+
"ArcFace": 0.65, # Standard High Security
|
| 8 |
+
"Facenet512": 0.40 # Standard High Security
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
# The absolute gate: Average score across models must be > 65%
|
| 12 |
+
REQUIRED_AVERAGE_CONFIDENCE = 65.0
|
| 13 |
+
|
| 14 |
+
# Advanced Quality Gate
|
| 15 |
+
MIN_FACE_AREA = 4000 # Rejects tiny background faces (slightly loosened)
|
| 16 |
+
|
| 17 |
+
# Application Configuration
|
| 18 |
+
COOL_DOWN_SEC = 5
|
| 19 |
+
LOG_FILE = "data/attendance_cloud.csv"
|
| 20 |
+
|
| 21 |
+
# Ensure directories exist
|
| 22 |
+
if not os.path.exists("data"):
|
| 23 |
+
os.makedirs("data")
|
| 24 |
+
if not os.path.exists("faces_db"):
|
| 25 |
+
os.makedirs("faces_db")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|