Most "rate my face" sites work the same way: you upload a selfie, a server does something with it, and a number comes back. We wanted the number without the upload. This is a write-up of how How Attractive Am I does the whole analysis in the browser, and the three things that turned out to be harder than the model itself.
The stack is boring on purpose
- Static HTML pages and vanilla JavaScript. No framework.
- MediaPipe Face Landmarker for the 478 face landmarks. The model file and the WASM runtime are served from our own domain.
- One Cloudflare Worker with a D1 database for anonymous statistics.
The model is only fetched after someone taps "Take a selfie" or picks a file, so a visitor who just reads the page never downloads it.
const landmarker = await FaceLandmarker.createFromOptions(fileset, { baseOptions: { modelAssetPath: '/models/face_landmarker.task', delegate: 'CPU' }, runningMode: 'IMAGE', numFaces: 2, outputFaceBlendshapes: true, }); numFaces: 2 looks odd for a tool that scores one face. It is there so we can detect a second person in the frame and ask for another photo instead of silently scoring whoever the model found first.
Problem 1: landmarks are normalised, faces are not square
MediaPipe returns x and y between 0 and 1. If you compute a ratio straight from those, a portrait photo and a square crop of the same face give different answers, because one unit of x and one unit of y are different numbers of pixels.
The fix is one line, and it is the first thing the measuring code does:
const pts = landmarks.map((p) => [p.x * width, p.y * height, (p.z ?? 0) * width]); z uses the same scale as x. Everything after that works in pixels and outputs only ratios and angles, never coordinates.
Problem 2: a small head turn wrecks symmetry
Symmetry is measured by comparing matching points on the left and right of the face. Turn your head a few degrees and the far side gets narrower in the image, so a symmetric face looks lopsided.
We use the 3D landmarks to rotate the face back to frontal before measuring. That helps, but only for small angles. On our test photos, when we kept only shots with less than 5° of turn, the same person's score moved by at most 0.4 between photos. Once photos turned more than 8° were allowed, we saw differences of 2.0 for the same person.
The obvious answer is to reject anything over 5°. The problem: 38% of our sample photos were turned more than that. Rejecting them all means more than a third of people get told to retake the photo.
So there are two thresholds:
yaw: { provisional: 5, reject: 10 }, Between 5° and 10° you still get a score, with a note that it is a rough one. Above 10° the page asks for another photo. We also tried correcting the symmetry number linearly by the turn angle. It did not work.
Problem 3: proving the photo stays on the device
"Runs in your browser" is easy to write and easy to break. Three things can quietly leak a face: your own API calls, your analytics, and a session-recording script.
Our own API. The browser sends back scores, the measurements (ratios and angles), the face shape and the photo-quality result. The Worker validates every request against a whitelist of fields, and the same module builds the payload in the browser:
// keys must match the spec exactly: no more, no fewer const obj = (spec, opt = {}) => (v) => { const keys = Object.keys(v); if (keys.some((k) => !(k in spec) && !(k in opt))) return false; ... }; One extra field and the whole record is rejected. If someone later adds landmarks to the payload by mistake, nothing is stored.
Session recording. We use Microsoft Clarity. Before turning it on we intercepted its requests locally and found that, without masking, the result images were uploaded whole. Adding the mask attribute from a script afterwards did not help. It has to be in the page source:
<section id="result" data-clarity-mask="true" hidden> We now have a check that runs the full flow with Clarity's requests intercepted and fails if any data:image or blob: URL shows up in what it tries to send.
The bug the whitelist caused
Strict validation has a cost. The face-shape classifier can output oblong. The whitelist on the server had been typed out by hand, and it said long. Every result with that face shape was rejected by our own server, with no error shown to the user. That was roughly a quarter of all results, from the first day.
The fix was not to correct the word. It was to delete the second list: the whitelist now imports the shape names from the classifier module, and a test asserts the two are identical. If a server validates against a list, that list should exist in exactly one place.
What the score is and is not
The number describes how balanced the proportions are in one photo. It moves with lighting, lens distance and head angle, which is why every result shows a margin of ±0.3. It says nothing about style, skin or personality, and it is not a prediction of how people see you in person.
Disclosure: this post was written by the AI coding agent that works on this project, checked against the project's source code and test logs, and approved by the maintainer before publishing.