PostureCoach
A real-time, browser-only posture monitor. It uses your webcam and two
Google MediaPipe models — Pose (33 body landmarks) and Face
Detection — to tell you when you're slouching or sitting too close to
the screen. Nothing is uploaded anywhere; all processing happens locally
in the browser.
Files
| File |
Purpose |
index.html |
Page structure: camera stage, dashboard cards, settings |
style.css |
All visual styling (dark, responsive layout) |
script.js |
Camera handling, MediaPipe setup, angle math, dashboard logic |
How it works, simply
- Camera —
script.js asks the browser for webcam access and plays
the video into a hidden <video> element.
- Pose model — every animation frame, the current video frame is sent
to MediaPipe Pose, which returns 33 body landmarks (nose, shoulders,
hips, knees, etc.), each as an
(x, y, visibility) value.
- Angles — using the shoulder, hip and ear landmarks, the app
calculates three angles measured from a perfectly vertical or
horizontal line:
- Neck tilt — how far the ears lean forward of the shoulders.
- Torso lean — how far the shoulders lean forward of the hips.
- Shoulder tilt — how uneven the two shoulders are.
If neck tilt or torso lean go past their limit, the frame is marked
"bad posture."
- Face Detection model — every second frame is also sent to
MediaPipe Face Detection, which returns a bounding box around the
face. If that box covers more than ~20% of the frame area, the face is
judged to be too close to the camera.
- Skeleton overlay — a
<canvas> sits on top of the video and draws
the skeleton lines using MediaPipe's POSE_CONNECTIONS list, colored
green (good), red (bad) or amber (face too close).
- Dashboard — a circular gauge shows the running "good posture %",
alongside session time, good/bad frame counts, live angle bars, and a
scrolling alert log.
Run it locally
Because browsers block webcam access on plain file:// pages, serve the
folder with any simple local server, for example:
cd posturecoach
python3 -m http.server 8080
Then open http://localhost:8080 in your browser and click Start
Camera.
Deploy to Hugging Face Spaces
- Create a new Space at huggingface.co/new-space.
- Choose Static as the Space SDK.
- Upload
index.html, style.css, script.js, and this README.md to
the Space's file list (or push them with git to the Space's repo) —
all four files go in the root of the repository, no subfolders.
- The Space will build automatically and give you a live URL. Because
it's HTTPS, the browser will allow webcam access.
Testing checklist