How luunhattien2005/streamlit_aiot works
Purpose and Entrypoint
This is a Streamlit-hosted face-recognition door-access dashboard. Its deployed/local entrypoint is source/streamlit_app.py, launched with Streamlit. It combines an operator UI, a polling recognition engine, registration workflow, and access-history dashboard.
Streamlit Application Shell
source/streamlit_app.py owns the three-tab UI and coordinates application actions:
• Background-like auto-refresh polling for pending door requests.
• Access-history presentation.
• Face enrollment from uploaded images.
• Styling is supplied by source/style.css.
The engine executes within the Streamlit runtime rather than as a separately deployed worker, so recognition processing depends on an active app session/refresh cycle.
Door Request Processing Pipeline
Pending access requests originate outside the repository from an ESP32-CAM device. The device uploads a captured image to ImgBB, then creates a Firebase new_request record containing an image URL and pending status.
The application flow is:
1. Read pending requests through source/firebase_manager.py.
2. Download/process the image and derive a facial embedding through source/face_engine.py.
3. Compare it with all registered embeddings using cosine distance and the documented 0.68 threshold.
4. Mark the request completed and append an allow/deny result to history_log.
This separates device/image transport (ESP32-CAM and ImgBB) from recognition logic and durable state (Firebase).
Face Recognition Domain Layer
source/face_engine.py is the AI boundary. It extracts face vectors using DeepFace with the VGG-Face model and performs matching against enrolled embeddings. It must handle the important failure boundary where an uploaded/request image has no usable face or cannot be processed; downstream persistence should receive a rejection/unknown result rather than a successful match.
Enrollment follows the same embedding-generation path: an operator supplies a name and image in source/streamlit_app.py, then the generated vector is persisted as a registered identity.
Persistence and Mock Boundary
source/firebase_manager.py abstracts Firebase Realtime Database access and provides the project’s mock-mode fallback when Firebase secrets are unavailable. It is responsible for the logical database branches:
• new_request: device-originated pending/completed work queue.
• registered: identity names and embeddings.
• history_log: recognition/audit outcomes.
The local example/store artifact source/Face_Database/registered_db.json may support development data, but Firebase is the intended shared production datastore. Firebase credentials are expected via Streamlit secrets, not repository files.
Data Model and Audit Flow
Registered users are represented by a user ID, display name, and numeric embedding. A request carries its ID, image URL, and lifecycle status. Completion produces an immutable-style history entry containing timestamp, image URL, matched name or unknown identity, door action, and face bounding box. This preserves an audit trail independent of mutable request status.
Runtime and External Dependencies
The application runs on Python 3.13 with Streamlit and AI/database dependencies declared in requirements.txt. Material services are Firebase Realtime Database, ImgBB-hosted request images, DeepFace/VGG-Face inference, and the ESP32-CAM producer. Deployment targets Streamlit hosting, with source/streamlit_app.py fixed as the configured main file.
Main entry points: firebase_manager.py Firebase Manager · face_engine.py Face Engine · streamlit_app.py Dashboard Shell · style.css Dashboard Styles
Components 14
Streamlit Runtime
Recognition runs during active app refresh cycles.
- Dashboard Shell · Three-tab operator UI, enrollment, history, and polling coordination.
source/streamlit_app.py - Dashboard Styles
source/style.css - Python Dependencies · Python 3.13 Streamlit, AI, and database dependencies.
requirements.txt
Recognition Domain
- Firebase Manager · Firebase access with mock-mode fallback.
source/firebase_manager.py - Face Engine · Generates embeddings and turns failures into unknown/rejected outcomes.
source/face_engine.py - DeepFace VGG-Face · Extracts face vectors from enrollment and request images.
- Cosine Matcher · Compares enrolled vectors using the 0.68 threshold.
source/face_engine.py
Data & External Services
- ESP32-CAM · Captures door-access images.
- ImgBB · Hosts captured request images.
- Firebase Realtime DB · Production state store; credentials come from Streamlit secrets.
- new_request · Pending and completed door requests.
- registered · Names and facial embeddings.
- history_log · Immutable-style allow/deny recognition outcomes.
- Local registered DB · Optional development registration data.
source/Face_Database/registered_db.json
Connections 20
- ESP32-CAM → ImgBB: uploads capture
- ESP32-CAM → new_request: creates pending request
- ImgBB → new_request: image URL
- Dashboard Shell → Firebase Manager: polls, enrolls, shows history
- Dashboard Shell → Face Engine: submits enrollment and requests
- Dashboard Styles → Dashboard Shell: styles UI
- Python Dependencies → Dashboard Shell: provides runtime
- Firebase Manager → Firebase Realtime DB: reads and writes
- Firebase Manager → Local registered DB: mock/development fallback
- Firebase Realtime DB → new_request: stores branch
- Firebase Realtime DB → registered: stores branch
- Firebase Realtime DB → history_log: stores branch
- new_request → Face Engine: pending image URL
- Face Engine → DeepFace VGG-Face: extracts embedding
- Face Engine → Cosine Matcher: request embedding
- registered → Cosine Matcher: enrolled embeddings
- Cosine Matcher → Firebase Manager: allow, deny, or unknown result
- Firebase Manager → new_request: marks completed
- Firebase Manager → history_log: appends audit outcome
- Face Engine → registered: persists enrollment vector