# filename: face_rating_app.py
import streamlit as st
import numpy as np
import dlib
import cv2
from PIL import Image
# Load pre-trained face detector and shape predictor
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat') # Download this file separately
def detect_landmarks(image):
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
faces = detector(gray)
if len(faces) == 0:
return None
landmarks = predictor(gray, faces[0])
points = []
for n in range(0, 68):
x = landmarks.part(n).x
y = landmarks.part(n).y
points.append((x, y))
return points
def calculate_symmetry(points):
# Simple symmetry measure: compare left vs right face landmarks
left = points[0:17] # Jawline left
right = points[16:0:-1] # Jawline right (reversed)
diffs = [np.linalg.norm(np.array(l) - np.array(r)) for l, r in zip(left, right)]
symmetry_score = 100 - np.mean(diffs)
…