Web AppProjects

Live Commerce Host Monitor

Internal computer vision research that replaces hours of rewatching streams with live KPIs readable second by second. Built from validated pretrained models, calibrated against bias with multimodal fusion, and designed around the privacy of the people being measured.

11 min read

An internal R&D prototype that chains 4 computer vision models into one pipeline: detect faces in a live stream (a live commerce platform), recognize who they are, read 7 emotion classes, measure engagement (smiling, talking, looking at the camera), then summarize it as live KPIs and a session report, so the team sees the big picture without rewatching the video.

Electron + ReactFastAPI + WebSocketPyTorch / MPSMTCNN + FaceNetViT / FER+MediaPipe FaceMeshYOLOv8-clsChart.js
Empathize · Define

The problem

A single live commerce session runs for hours. How do you know when the host still has energy and where engagement drops, without rewatching the whole thing?

A phone on a tripod streaming live, showing the host on screen
One live session runs for hours. How do you tell where the host still has energy? · Photo: Detail .co / Unsplash

The ops team wanted to understand how engaged each host is with the camera and how their mood shifts across a session. Having someone rewatch hours of video and score it by hand is slow, always late and subjective. The brief: make these metrics readable second by second, automatically, while respecting the privacy of the people being measured.

— The starting brief for the host analysis research

Streams run for hours, too long to rewatch

A selling session lasts hours. Nobody rewatches the whole clip to assess engagement. The team needed per-second metrics that summarize instantly.

"Is the host losing energy?" Human eyes can't keep up

A host's mood and activity change constantly. Scoring by eye is subjective and patchy. We wanted a signal that can be measured as a number.

Off-the-shelf FER models are biased

Emotion models trained on standard datasets tend to read a neutral or talking face as sad or angry. Used as-is, the numbers are wrong from the start.

Knowing who is on screen means preparing photos in advance

Typical face recognition needs a set of reference photos for each person first. That is a hassle when several hosts rotate in and out. We wanted to register people live, on the spot.

Faces and emotions are sensitive biometric data

Processing face embeddings and personal emotions counts as biometric data under PDPA (Thailand's data protection law). Without designing for consent, retention and storage from day one, it becomes a liability.


Ideate

The solution

Let a CV pipeline do the heavy lifting: detect, recognize, read emotion and measure engagement on every frame, then summarize it as KPIs a person can read in 3 seconds

A green box around a face labeled host_01 happy 82%, with per-minute energy, smile, talking, looking and frown values
Overlay from the real app: face box, name from enrollment, emotion and 1-minute signals (the sample is an AI presenter, not a real host)

Real-time pipeline: face → identity → emotion → engagement

Every frame runs continuously through MTCNN (finds faces) → FaceNet (identity embedding) → ViT (7 emotion classes) → MediaPipe FaceMesh (smiling, talking, looking at camera)

Readable KPIs with a rolling window

The output is Energy / Smile / Talking / Looking / Mood with 1-minute and 5-minute moving averages, so you can see live whether things are trending up or down

Click-to-enroll: register identities live

Click a face in the video, type a name, press Enter. The embedding is averaged into a file and works immediately. No reference photo set needed in advance.

Multimodal calibration to correct a single model's bias

Geometric signals from FaceMesh (smile and frown blendshapes) gate the ViT output, so neutral faces stop reading as sad and real smiles come through more clearly

Local-only and PDPA-aware by design

Face embeddings and all logs stay on the machine (gitignored) and are never sent out. Consent, retention windows and access limits were planned from the start.


Prototype

How it works, in 4 steps

From a live video frame to live KPIs on the dashboard

Pipeline diagram from the README: MTCNN, FaceNet, MediaPipe FaceMesh, ViT emotion, calibration, EMA and report
The actual pipeline from the README: 4 models chained on each frame, then smoothed into 1- and 5-minute metrics
1

Grab live frames

Electron embeds a real browser to open the stream, captures the screen as frames and sends them to the backend over WebSocket

2

Detect and recognize faces

MTCNN finds faces → FaceNet produces a 512-d embedding → cosine match against enrolled identities

3

Read emotion and engagement

ViT classifies 7 emotions, FaceMesh reads blendshapes as smiling, talking and looking at camera, and the two are calibrated together

4

Summarize KPIs and log

Combined into live KPIs in the sidebar, plus a per-frame CSV that later becomes the session report


Prototype

Tech Stack & Architecture

The desktop app talks to a local Python ML backend over WebSocket. Everything is processed locally, no cloud.

Sample rows from the per-frame CSV log: time, track id, emotion, confidence, smile/talk/look signals and box coordinates
Per-frame log from a real session file (no name enrolled = unknown), the raw material for the report and charts
Live video source: a live commerce platform
Embedded Chromium Screen frame (JPEG) Comment / Gift / Like
↕
Python ML Backend — FastAPI + WebSocket
MTCNN (detect) FaceNet / VGGFace2 ViT / FER+ MediaPipe FaceMesh
↕
Tracking & Calibration
IoU face tracking EMA smoothing neutral-bias smile / frown gate
↕
Electron + React Desktop — Live KPI + Session Report
KPI sidebar (rolling 1m/5m) per-frame CSV log Chart.js report
Why this stack?

FastAPI + WebSocket: low-latency two-way frame streaming, suited to continuous inference · Electron WebContentsView embeds a real browser to capture the stream and pull comments, gifts and likes in one app · Pretrained models (FaceNet / ViT / MediaPipe): building on validated models instead of training my own made the prototype faster to finish and more accurate · PyTorch + Apple MPS speeds things up on Apple Silicon, with a workaround that pins some models to the CPU to avoid an MPS bug


Prototype

What I built: 8 core capabilities

The full loop, from face detection to a session report the team can review later

App sidebar: host KPIs, live stats, likes, gifts, comment count and the comment feed
The real app's sidebar: host KPIs, live stats and pulled comments (sample data)

Face Detection & Recognition

MTCNN finds faces, FaceNet/VGGFace2 produces a 512-d embedding, then cosine matching against enrolled identities

Emotion Classification

A Vision Transformer (fine-tuned on FER+) classifies 7 emotions: angry, disgust, fear, happy, neutral, sad, surprise

Engagement Signals

MediaPipe FaceMesh 52 blendshapes + head pose → geometric smile / talking / looking / frown / blink

Click-to-Enroll

Click a face in the video, type a name, press Enter → the embedding is averaged into a file and works immediately, no reference photos needed

Live KPI Sidebar

Energy / Smile / Talking / Looking / Mood with 1-minute and 5-minute rolling windows, updated live in the app

Comment & Gift Scraper

Pulls comments, gifts, likes and viewer count from the stream (via a live-comment connector) and shows them next to the emotion metrics

Session Report

Aggregates the per-frame CSV per host per minute into behavior and emotion-mix charts with Chart.js

Two-Model Research

Compares a custom-trained YOLOv8-cls against the pretrained ViT on the same task, to answer "is training our own worth it?"


Prototype

The desktop app

Open a stream in the app window and see the video, face boxes and live KPIs on one screen

The full Live Host Monitor window: KPI sidebar on the left, live video with face boxes on the right
The real Electron app UI (rendered from the actual renderer with sample data), compared with the mockup above
Live Host Monitor backend online · MPS

Live

host_01 · happy 82%
Energy74%
Smile61%
Talking68%
Looking88%
Frown7%
Mood+0.53

Stream

Viewers1.2k
❤/min3.4k
Comments146
Joins52
LIVE 1,204
host_01 · happy 82%
smile talking looking frown
@mint_shopDo you still have size M?

Test & Iterate

Hacking the problems

6 problems I had to solve myself: ML model bias, hardware quirks and real-time engineering

Session report: overall KPIs, a per-minute behavior chart and a per-minute emotion mix chart
A real session report from a 32,938-frame log. After calibration and EMA, the emotion chart is steady enough to read trends.

My own trained model read neutral faces as "angry"

The classifier fine-tuned on a public dataset had heavy class imbalance (one class had many times more images than another). On a real webcam it leaned toward the class with the most data, and neutral faces were read as angry with high confidence.

Fix: comparing per-class recall and testing live made the failure mode obvious, so I switched to a pretrained ViT (FER+) trained on a larger, more balanced dataset. Lesson: see point 2 in Knowledge Domain.

ViT still got stuck on "sad" for normal talking faces

The pretrained ViT was better, but it still stuck to negative emotions on neutral and talking faces, which pushed the mood score too negative.

Fix: use geometric signals from FaceMesh (frown and smile blendshapes) to "gate" the ViT output. With no evidence of a frown, negative emotion probabilities are damped; with a real smile, happy is boosted. Together this is a multimodal calibration that beats a single model's bias.

Emotion labels flickered from frame to frame

Reading each frame independently made labels jump between happy, neutral and sad constantly, and face identities swapped when people moved.

Fix: match faces across frames with IoU tracking so each face keeps a stable track id, then smooth the probability vector with an EMA per track. Labels settle, and metrics accumulate on the right person.

Face recognition needed a photo set before it worked

Standard identification needs reference photos of each person ahead of time. That breaks down when hosts change often.

Fix: click-to-enroll. The operator clicks a face in the live video, types a name and presses Enter. The system averages that frame's embedding into a file, and recognition works right away with no prior photo set.

Capturing the stream and pulling comments at the same time was hard

I wanted both the live video (to read faces) and live metadata (comments, gifts, viewers) in one app, without relying on hard-to-access APIs.

Fix: Electron WebContentsView embeds a real browser to open the stream → frames are captured and sent to the models, while a live-comment connector reads comment, gift, like and join events live. The view is kept positioned over a React placeholder at all times.

The face detector was the bottleneck, and it hit an MPS bug

Face detection was the slowest step in the pipeline, and the detector also hit an Apple MPS bug (pooling needs evenly divisible sizes) that made it hang.

Fix: pin the detector to the CPU to avoid the bug, run embedding and emotion on MPS, detect every other frame and process asynchronously over WebSocket. The result is about 8–12 FPS on an Apple M4 Pro, enough for live monitoring.

Define

Deliberate design decisions

Because this touches people's biometric data, what the system does not do matters as much as what it does

The .gitignore file that keeps face embeddings and session logs out of the repository
Local-only from day one: embeddings and logs are gitignored and never leave the machine

This is a research prototype that captures biometric data (face embeddings) and behavioral data (emotion and attention), so it was designed around PDPA principles from the start. All data stays on the machine and is never exported. The metrics are "signals" for an overview, not fixed judgments about a person, and the docs state the models' limitations and biases clearly. A real production version would always need consent, a retention window and access limits first.


Local-only, always

Embeddings and logs stay on the machine (gitignored), never sent out


PDPA-aware

Designed for consent · retention window · access control


Signals, not verdicts

Metrics are for an overview, labeled with the models' known biases


Honest about being a prototype

Calibration is hand-tuned and not yet validated on a labeled set


Level Up · Reflect

Knowledge domains that got stronger

5 areas where my skills actually moved up through this project

A screen showing a dashboard with several kinds of data charts
From several models to numbers a team can read and act on · Photo: Luke Chesser / Unsplash
1. Real-time computer vision pipelines: orchestrating several models to keep up with the frame rate:

I chained 4 models (detect → recognize → classify → mesh) to run within a single latency budget, including IoU tracking across frames and EMA smoothing. Lesson: real-time ML is a game of latency and output stability, not just a single model's accuracy number.

2. Model evaluation & the accuracy trap: headline accuracy can lie:

My own trained model had a nice top-1 score on the test set but failed in real use, because the test set inherited the class imbalance from training. Only per-class recall, a confusion matrix and live testing revealed the failure mode (neutral → angry). Lesson: one headline number can always hide a distribution problem.

3. Pretrained vs custom-trained: knowing when to train your own:

A direct comparison showed that a small CNN trained on a few thousand images can't compete with a ViT pretrained on a large dataset. Lesson: training your own is only worth it when (a) the label set is non-standard, (b) there is a measurable failure mode in the real domain, or (c) you have a data flywheel feeding it. Otherwise, pretrained is the right default.

4. Multimodal signal fusion: combining different signals beats a single model's bias:

Learned emotion from ViT is blended with geometric blendshapes from FaceMesh through a gate/bias/boost mechanism to cancel out the bias a single model has. Lesson: when one model is biased, adding an independent signal is often more robust than forcing a fine-tune of the same model.

5. Applied AI ethics / PDPA: responsible AI is a requirement, not a nice-to-have:

I designed a system that touches biometrics and emotion with consent, retention, local-only storage and documented model bias in mind from the start. Lesson: with sensitive personal data, ethical and legal correctness is a system requirement, not an add-on for later.

4
AI models in one pipeline
7
Emotion classes (FER+)
52
ARKit blendshapes from FaceMesh
8–12
Real-time FPS on Apple M4 Pro

Tan · Natpakan Sirirat

Product Designer & AI Builder — designing user experiences and building AI tools that actually work.

0%