File size: 1,989 Bytes
b9d5dd9
130d7c1
 
 
 
 
b9d5dd9
130d7c1
 
 
b9d5dd9
 
130d7c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
---
title: Face Shape Detection
emoji: 👤
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit
app_port: 7860
short_description: AI face shape detection with MediaPipe & ML
---

# Face Shape Detection

An AI-powered application that analyzes facial features to determine face shape using MediaPipe landmarks and machine learning.

## Features

- **Real-time face shape detection** from uploaded images
- **5 face shape categories**: Heart, Oval, Round, Square, Oblong
- **Facial measurements** with confidence scores
- **Interactive web interface** with image upload
- **RESTful API** for integration

## How it Works

1. **Face Detection**: Uses MediaPipe to detect and extract facial landmarks
2. **Feature Extraction**: Calculates key facial measurements and ratios
3. **ML Classification**: Uses a trained Random Forest model to predict face shape
4. **Results**: Returns face shape, confidence scores, and facial measurements

## API Endpoints

- `POST /analyze` - Upload an image for face shape analysis
- `GET /` - Web interface for image upload
- `GET /video_feed` - Real-time video feed (if camera available)

## Usage

1. Upload an image using the web interface
2. The system will analyze the face and return:
   - Detected face shape
   - Confidence scores for all categories
   - Facial measurements (length, width, etc.)
   - Annotated image with landmarks

## Technical Details

- **Framework**: Flask
- **Computer Vision**: MediaPipe, OpenCV
- **ML Model**: Random Forest (scikit-learn)
- **Image Processing**: Smart preprocessing with face detection
- **Deployment**: Docker container optimized for Hugging Face Spaces

## Model Performance

The model uses optimized features extracted from 468 facial landmarks and achieves high accuracy in face shape classification across diverse face types.

## Requirements

- Python 3.10+
- MediaPipe
- OpenCV
- scikit-learn
- Flask
- NumPy

## License

MIT License - feel free to use and modify for your projects.