| class BodyShapeDetector: | |
| def __init__(self): | |
| self.shape_characteristics = { | |
| 'hourglass': { | |
| 'characteristics': ['Balanced shoulders and hips', 'Defined waist', 'Curvy silhouette'], | |
| 'flattering_styles': ['Wrap dresses', 'Belted waists', 'Tailored fits'], | |
| 'avoid_styles': ['Boxy cuts', 'Sack dresses', 'Oversized shapes'], | |
| 'celebrities': ['Beyoncé', 'Scarlett Johansson', 'Sofia Vergara'] | |
| }, | |
| 'pear': { | |
| 'characteristics': ['Narrower shoulders', 'Wider hips', 'Smaller bust'], | |
| 'flattering_styles': ['A-line skirts', 'Boat necks', 'Statement sleeves'], | |
| 'avoid_styles': ['Skinny jeans', 'Low-rise pants', 'Pencil skirts'], | |
| 'celebrities': ['Rihanna', 'Jennifer Lopez', 'Kim Kardashian'] | |
| }, | |
| 'apple': { | |
| 'characteristics': ['Broader shoulders', 'Fuller midsection', 'Slimmer legs'], | |
| 'flattering_styles': ['Empire waist', 'V-necklines', 'Flowy tops'], | |
| 'avoid_styles': ['Crop tops', 'Tight waistbands', 'Belted waists'], | |
| 'celebrities': ['Adele', 'Oprah', 'Melissa McCarthy'] | |
| }, | |
| 'rectangle': { | |
| 'characteristics': ['Straight silhouette', 'Balanced proportions', 'Athletic build'], | |
| 'flattering_styles': ['Peplum tops', 'Belted jackets', 'Layered looks'], | |
| 'avoid_styles': ['Straight cuts', 'Monochrome outfits', 'Baggy clothes'], | |
| 'celebrities': ['Cameron Diaz', 'Natalie Portman', 'Keira Knightley'] | |
| }, | |
| 'inverted triangle': { | |
| 'characteristics': ['Broad shoulders', 'Narrower hips', 'Athletic build'], | |
| 'flattering_styles': ['V-necks', 'Flared pants', 'Pencil skirts'], | |
| 'avoid_styles': ['Shoulder pads', 'Boat necks', 'Halter tops'], | |
| 'celebrities': ['Naomi Campbell', 'Demi Moore', 'Angelina Jolie'] | |
| } | |
| } | |
| self.fit_recommendations = { | |
| 'hourglass': 'Highlight your waist with fitted pieces', | |
| 'pear': 'Balance your proportions with volume on top', | |
| 'apple': 'Create definition with V-necklines and empire waists', | |
| 'rectangle': 'Add curves with peplum and belted styles', | |
| 'inverted triangle': 'Add volume to lower half with A-line skirts' | |
| } | |
| def detect(self, measurements: dict) -> dict: | |
| shoulders = measurements.get('shoulders', 0) | |
| chest = measurements.get('chest', 0) | |
| waist = measurements.get('waist', 0) | |
| hips = measurements.get('hips', 0) | |
| shoulder_hip_ratio = shoulders / hips if hips > 0 else 1 | |
| waist_hip_ratio = waist / hips if hips > 0 else 1 | |
| shape = self._classify_shape(shoulder_hip_ratio, waist_hip_ratio) | |
| shape_data = self.shape_characteristics.get(shape, self.shape_characteristics['rectangle']) | |
| return { | |
| "shape": shape, | |
| "confidence": 0.85, | |
| "characteristics": shape_data['characteristics'], | |
| "flattering_styles": shape_data['flattering_styles'], | |
| "avoid_styles": shape_data['avoid_styles'], | |
| "fit_recommendations": self.fit_recommendations.get(shape, 'Choose styles that balance your proportions'), | |
| "celebrities": shape_data['celebrities'] | |
| } | |
| def _classify_shape(self, shoulder_hip_ratio: float, waist_hip_ratio: float) -> str: | |
| if 0.95 <= shoulder_hip_ratio <= 1.05 and waist_hip_ratio < 0.75: | |
| return 'hourglass' | |
| elif shoulder_hip_ratio < 0.95 and waist_hip_ratio > 0.75: | |
| return 'pear' | |
| elif shoulder_hip_ratio > 1.05 and waist_hip_ratio > 0.85: | |
| return 'apple' | |
| elif 0.95 <= shoulder_hip_ratio <= 1.05 and 0.75 <= waist_hip_ratio <= 0.85: | |
| return 'rectangle' | |
| elif shoulder_hip_ratio > 1.05 and waist_hip_ratio < 0.75: | |
| return 'inverted triangle' | |
| else: | |
| return 'rectangle' |