vrfefavr commited on
Commit
e0d48a6
·
verified ·
1 Parent(s): 8ac215f

Update core/config.py

Browse files
Files changed (1) hide show
  1. 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
- # --- 🛡️ SHIELDS ---
14
- os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
15
- os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
16
-
17
- # --- 🩹 Keras Monkey Patch ---
18
- import tensorflow as tf
19
- import keras
20
- import sys
21
- sys.modules['tensorflow.keras'] = keras
22
- sys.modules['tensorflow.keras.layers'] = keras.layers
23
- sys.modules['tensorflow.keras.models'] = keras.models
24
-
25
- from deepface import DeepFace
26
-
27
- # Custom Modules
28
- from core.config import LOG_FILE, MODELS
29
- from core.state import attendance_memory
30
- from api.websocket import websocket_endpoint
31
-
32
- @asynccontextmanager
33
- async def lifespan(app: FastAPI):
34
- # --- STARTUP PHASE ---
35
- # Load historical logs into RAM
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")