File size: 1,928 Bytes
318219d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
title: AIFaceShapeDetector
emoji: 
colorFrom: blue
colorTo: gray
sdk: gradio
sdk_version: 6.5.1
app_file: app.py
pinned: false
license: cc-by-nc-4.0
short_description: Smple Face Shape Detection using Mediapipe and ML
---

## AI Face Shape Detector (Hugging Face Space)

Upload a front-facing photo (or use your webcam) and this Space predicts your **face shape** and shows a **MediaPipe face-mesh overlay** plus **confidence scores**.

Full app available at [attractivenesstest.com/face_shape](https://attractivenesstest.com/face_shape).

### Supported face shapes

- **Oval**
- **Round**
- **Square**
- **Heart**
- **Oblong**

### How it works (from `app.py`)

- **Face landmark extraction**: Uses **MediaPipe Face Mesh** (up to **478 landmarks**) to detect a single face.
- **Landmark normalization**: Centers landmarks using the eye/iris center, applies roll correction, and scales by inter-eye distance.
- **Classification**: Flattens normalized landmark coordinates and runs a **pickled scikit-learn classifier** (loaded from `face_shape_model.pkl`) with a label encoder (`label_encoder_rf.pkl`).
- **Outputs**:
  - An image with a face mesh/contour overlay
  - A formatted result card (shape + description + styling tip)
  - Per-class confidence scores

### Tips for best results

- Use a **front-facing** photo with good lighting
- Ensure your **entire face** is visible
- Remove glasses if possible
- Avoid tilting your head

### Run locally

```bash
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python app.py
```

Then open the Gradio URL printed in your terminal.

### Notes / limitations

- This demo expects **one clear, visible face** in the image (`max_num_faces=1`).
- If no face is detected, the app will return an error message asking for a clearer photo.
- Uploaded images are processed in-memory by the app; the code does not intentionally save uploads to disk.

---