AI-powered face shape analysis & personalised hairstyle + beard style recommendations
Built with Python · Flask · MediaPipe · MongoDB · Gemini · Replicate
HairStyle AI is a web application that analyses a user's face shape from a photo and instantly recommends the most flattering hairstyles and beard styles. It uses Google's MediaPipe to detect 468 facial landmarks, classifies the face shape, and provides curated style recommendations — complete with an AR Try-On feature powered by Replicate's image generation API.
| Feature | Description |
|---|---|
| 📸 Face Shape Analysis | Upload a photo — AI detects your face shape (Oval, Round, Square, Heart, Diamond, Oblong) |
| 💇 Hairstyle Recommendations | Get personalised hairstyle suggestions tailored to your face shape |
| 🧔 Beard Style Recommendations | Beard style recommendations matched to your facial structure |
| 🪞 AR Try-On | Virtually try styles on your webcam feed using AI-generated overlays |
| 🤖 AI Chatbot | Built-in rule-based chatbot to guide users |
| 📜 Analysis History | Every analysis is saved to your personal dashboard |
| 🔐 Auth System | Secure register/login with bcrypt password hashing |
| 🎭 Auto Gender Detection | Gemini Flash Lite auto-detects gender from the uploaded photo |
Backend : Python 3.10+, Flask 2.3, Gunicorn
AI/CV : MediaPipe 0.10, OpenCV (headless), TensorFlow 2.13, DeepFace
APIs : Google Gemini Flash Lite (gender detection), Replicate (AR style generation)
Database : MongoDB (Atlas for cloud, localhost for dev)
Auth : Flask-Bcrypt, Flask-Login
Frontend : Vanilla HTML/CSS/JS (Jinja2 templates)
Deployment : Render (render.yaml included)
Upload your photo → get your face shape → see personalised style recommendations → try them on live via AR.
- Python 3.10+
- MongoDB running locally (
mongod) - A Gemini API key (get one free)
- A Replicate API token (get one free)
git clone https://github.com/YOUR_USERNAME/hairstyle-ai.git
cd hairstyle-aipython -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activatepip install -r requirements.txtcp .env.example .envEdit .env and fill in your values:
SECRET_KEY=your_random_secret_key
MONGO_URI=mongodb://localhost:27017/hair_beard_ai
GEMINI_API_KEY=your_gemini_api_key
REPLICATE_API_TOKEN=your_replicate_token
DEBUG=Truepython app.pyOpen http://localhost:5000 in your browser.
This repo includes a render.yaml for one-click deployment.
- Push this repo to GitHub
- Go to render.com → New → Web Service
- Connect your GitHub repo
- Render auto-detects
render.yaml— review settings and confirm - Add these Environment Variables in the Render dashboard:
| Variable | Value |
|---|---|
SECRET_KEY |
Any random 32-char string |
MONGO_URI |
Your MongoDB Atlas connection URI |
GEMINI_API_KEY |
Your Gemini API key |
REPLICATE_API_TOKEN |
Your Replicate token |
DEBUG |
False |
- Click Deploy — your app will be live in ~3 minutes ✅
MongoDB Atlas: For cloud deployment, use a free MongoDB Atlas cluster. Make sure to whitelist
0.0.0.0/0in Network Access.
hairstyle-ai/
│
├── app.py # Application factory
├── wsgi.py # Gunicorn/WSGI entry point
├── config.py # Configuration (reads from .env)
├── database.py # MongoDB connection module
│
├── routes/
│ ├── auth.py # Register, Login, Logout
│ ├── analysis.py # Face analysis, AR snapshot, history
│ └── chatbot.py # AI chatbot API endpoint
│
├── utils/
│ ├── face_utils.py # MediaPipe face landmark analysis
│ ├── gender_detector.py # Gemini-based gender auto-detection
│ ├── style_preview.py # AR Try-On rendering (Replicate + OpenCV)
│ └── style_recommender.py# Face-shape → style mapping engine
│
├── templates/ # Jinja2 HTML templates
├── static/ # CSS, JS, images, uploads
│
├── requirements.txt # Python dependencies
├── Procfile # Render/Heroku start command
├── render.yaml # Render deployment config
└── .env.example # Environment variable template
| Variable | Required | Description |
|---|---|---|
SECRET_KEY |
✅ | Flask session secret (use a long random string) |
MONGO_URI |
✅ | MongoDB connection URI |
GEMINI_API_KEY |
✅ | Google Gemini API key for gender detection |
REPLICATE_API_TOKEN |
✅ | Replicate token for AR image generation |
UPLOAD_FOLDER |
❌ | Default: static/uploads |
MAX_CONTENT_LENGTH |
❌ | Default: 16777216 (16 MB) |
DEBUG |
❌ | Default: False (set True for local dev) |
S. Thiruselvam (Roll No: 23COS263)
AI-powered personal styling assistant — built as a final-year project using Python, Flask, MediaPipe, and MongoDB.
This project is for educational purposes. All rights reserved © 2024 S. Thiruselvam.