lifedebugger's picture
Deploy files from GitHub repository with LFS
e249c2c
|
Raw
History Blame Contribute Delete
4.06 kB
# FaceGuard β€” Advanced Face Recognition Attendance System
## Original Problem Statement
User needs improved face recognition that cannot be bypassed by photos or videos. Wants immigration-style face mesh with colorful lines, liveness challenges (blinking, etc), highly accurate and production-ready. Existing codebase was HuggingFace Space FastAPI face-verify with `uniface` + `MiniFASNetV2` (bypassable, no challenge-response liveness, no attendance features).
## Architecture
### Backend β€” `/app/backend/server.py` (FastAPI on :8001)
- **RetinaFace** face detector (uniface)
- **ArcFace buffalo_l** identity embeddings (512-d, cosine sim threshold 0.42)
- **MiniFASNetV2 ONNX** texture-based anti-spoof (defeats screen replays)
- **Server-side challenge tokens** (in-memory, 120s TTL, single-use) β€” cannot bypass by replaying without doing the actions
- **MongoDB** for employees (with embeddings) + attendance logs
### Frontend β€” `/app/frontend` (React 18 + Tailwind on :3000)
- **MediaPipe Face Mesh (468 pts)** live in browser via CDN
- Animated **gradient mesh overlay** (violet β†’ blue β†’ cyan β†’ green) with laser sweep + corner brackets (airport-kiosk aesthetic)
- **Client-side liveness detection** using landmark math:
- Blink β†’ Eye Aspect Ratio (EAR)
- Turn left / right β†’ Yaw estimation from nose vs cheeks
- Nod β†’ Pitch estimation from nose vs forehead/chin
- Smile / mouth open β†’ Mouth Aspect Ratio + width vs cheeks
- Randomized 3-challenge sequences per session (issued by backend)
- Framer Motion transitions, Sonner toasts, dark cyber theme
## Three-Layer Anti-Spoof Chain
1. **Client challenge-response** (MediaPipe) β€” user must do 3 randomized actions live β†’ defeats static photos
2. **Server MiniFASNetV2 texture CNN** β†’ defeats printed photos & screen replays
3. **Server ArcFace cosine match** β†’ identity binding
## Pages
- `/` Landing β€” bento grid, 3-layer tech pitch, hero with scanner image, metric cards
- `/register` β€” 3-step: identity form β†’ capture 3 samples with liveness β†’ success
- `/attendance` β€” Kiosk-style check-in/check-out with GPS, live mesh scanner, result screen with match/live scores
- `/admin` β€” Stats (total/present/late/absent), attendance log table w/ snapshots + GPS, employee cards, CSV export
## API Endpoints
- `GET /api/health`
- `POST /api/attendance/challenge` β†’ random 3 actions + token
- `POST /api/employees` β€” enroll (multiple images β†’ embeddings)
- `GET /api/employees` / `GET /api/employees/{id}` / `DELETE /api/employees/{id}`
- `POST /api/face/verify` β€” verify one frame (challenge_token required to strengthen)
- `POST /api/attendance` β€” record check-in/out (challenge_token required, GPS metadata)
- `GET /api/attendance?date&employee_id` / `GET /api/attendance/{id}`
- `GET /api/attendance/stats/summary?date`
- `GET /api/attendance/export/csv?date&employee_id`
## What's Implemented (2026-07-31)
- Full 3-layer face recognition & anti-spoofing pipeline (client + server)
- Employee enrollment with real ArcFace embedding storage
- Attendance record with GPS + face snapshot
- Admin dashboard with stats, filterable log table, employee CRUD, CSV export
- Live gradient MediaPipe face mesh overlay + laser sweep + corner brackets (immigration-style)
- Random liveness challenges: blink, turn left, turn right, nod, smile
- All backend flows tested end-to-end via curl (register β†’ verify β†’ check-in β†’ stats β†’ CSV export β†’ delete)
## Prioritized Backlog (P0 β†’ P2)
- P1: Store embeddings via secure hashing / normalize thumbnails
- P1: Configurable working hours & late threshold (currently hardcoded 09:00 UTC)
- P2: WebSocket streaming verification for even faster kiosk UX
- P2: Multi-factor: NIK / QR fallback when face fails
- P2: Facial re-enrollment reminder after N months
- P2: Admin auth (currently open)
## Tech Stack
FastAPI Β· uniface (InsightFace ArcFace) Β· onnxruntime Β· MiniFASNetV2 Β· OpenCV Β· MongoDB (motor) Β· React 18 Β· Tailwind Β· MediaPipe Face Mesh Β· Framer Motion Β· Sonner Β· Lucide React