Download services/recommendation_engine.py from Mohansree/bsure-api: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/spaces/Mohansree/bsure-api/resolve/main/services/recommendation_engine.py
- Command line
-
hf download hf://spaces/Mohansree/bsure-api/services/recommendation_engine.py
-
curl -L -o recommendation_engine.py https://huggingface.co/spaces/Mohansree/bsure-api/resolve/main/services/recommendation_engine.py
2.15 kB
| import random | |
| from models import WardrobeItem | |
| class RecommendationEngine: | |
| def __init__(self, items: list[WardrobeItem]): | |
| self.items = items | |
| self.tops = [i for i in items if i.category.lower() == "top"] | |
| self.bottoms = [i for i in items if i.category.lower() == "bottom"] | |
| self.shoes = [i for i in items if i.category.lower() == "shoes"] | |
| def generate(self, style: str = "any"): | |
| """ | |
| Generates a recommended outfit structure. | |
| Returns: { "items": [List of Objects], "note": "Style Note" } | |
| """ | |
| if not self.tops or not self.bottoms: | |
| return None | |
| # 1. Pick Core (Top + Bottom) | |
| # TODO: Advanced Logic - match tags (color, season) | |
| # For now, random selection from available items is the MVP | |
| top = random.choice(self.tops) | |
| bottom = random.choice(self.bottoms) | |
| outfit_items = [top, bottom] | |
| # 2. Add Shoes if available | |
| shoes = None | |
| if self.shoes: | |
| shoes = random.choice(self.shoes) | |
| outfit_items.append(shoes) | |
| # 3. Generate Note | |
| note = self._generate_note(top, bottom, shoes, style) | |
| return { | |
| "items": outfit_items, | |
| "note": note | |
| } | |
| def _generate_note(self, top, bottom, shoes, style): | |
| # Infer style from tags | |
| is_denim = "jean" in (bottom.tags or "").lower() | |
| is_tee = "tee" in (top.tags or "").lower() or "t-shirt" in (top.tags or "").lower() | |
| if is_denim and is_tee: | |
| return "Classic Casual: Timeless denim paired with a comfortable tee." | |
| elif is_denim: | |
| return "Smart Casual: Upgraded denim look." | |
| elif style == "formal": | |
| return "Sharp & Professional: Ready for business." | |
| elif style == "party": | |
| return "Evening Ready: A look that stands out." | |
| if shoes: | |
| return "Head-to-Toe Look: Complete outfit with matching footwear." | |
| return "Daily Essential: A versatile combination from your wardrobe." | |