Spaces:
Build error
Build error
smagen10
commited on
Commit
·
afb91b1
1
Parent(s):
2759de1
all files done
Browse files- README.md +44 -4
- models/.DS_Store +0 -0
- models/__pycache__/llm.cpython-312.pyc +0 -0
- models/__pycache__/vision.cpython-312.pyc +0 -0
- models/llm.py +83 -0
- models/vision.py +50 -0
- utils.zip +3 -0
README.md
CHANGED
|
@@ -1,13 +1,53 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.29.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
short_description:
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: StyleSavvy
|
| 3 |
+
emoji: 🏆
|
| 4 |
+
colorFrom: gray
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.29.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
short_description: Style Savvy - AI Style Fashion Consultant
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 14 |
+
|
| 15 |
+
# 👗 StyleSavvy — AI Fashion Consultant
|
| 16 |
+
|
| 17 |
+
StyleSavvy is an AI-powered virtual stylist that uses computer vision and natural language generation to give personalized fashion advice.
|
| 18 |
+
|
| 19 |
+
## ✨ Features
|
| 20 |
+
- Detects clothing from uploaded photos using YOLOS-Fashionpedia
|
| 21 |
+
- Removes background for better detection (optional)
|
| 22 |
+
- Provides tailored styling tips based on:
|
| 23 |
+
- Body type
|
| 24 |
+
- Face shape
|
| 25 |
+
- Gender
|
| 26 |
+
- Occasion
|
| 27 |
+
- Uses `google/flan-t5-large` to generate expert-level suggestions
|
| 28 |
+
|
| 29 |
+
## 📸 How to Use
|
| 30 |
+
1. Upload a clear photo of your outfit
|
| 31 |
+
2. Select your body type, face shape, and gender
|
| 32 |
+
3. Enter the event or occasion
|
| 33 |
+
4. Click **Generate Style Tips**
|
| 34 |
+
5. Enjoy your personalized fashion advice! 🪞
|
| 35 |
+
|
| 36 |
+
## 🛠️ Tech Stack
|
| 37 |
+
- Gradio UI
|
| 38 |
+
- Hugging Face Transformers
|
| 39 |
+
- YOLOS object detection
|
| 40 |
+
- FLAN-T5 language model
|
| 41 |
+
- remove.bg API for optional background removal
|
| 42 |
+
|
| 43 |
+
## 🧠 Example Use Case
|
| 44 |
+
> “A curvy woman with a round face going to a summer wedding”
|
| 45 |
+
> → StyleSavvy suggests breathable floral fabrics, statement earrings, and pastel tones that match the event ambiance.
|
| 46 |
+
|
| 47 |
+
## 🔐 API Key
|
| 48 |
+
Make sure to add a Hugging Face **Secret**:
|
| 49 |
+
- `REMOVE_BG_API_KEY`: your remove.bg key
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
🚀 Try it live: [StyleSavvy on Hugging Face](https://huggingface.co/spaces/Munazz/StyleSavvy)
|
models/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
models/__pycache__/llm.cpython-312.pyc
ADDED
|
Binary file (3.96 kB). View file
|
|
|
models/__pycache__/vision.cpython-312.pyc
ADDED
|
Binary file (1.67 kB). View file
|
|
|
models/llm.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from typing import List
|
| 4 |
+
|
| 5 |
+
PROMPTS = {
|
| 6 |
+
"category_expansion": (
|
| 7 |
+
"As a top-tier fashion advisor, craft one impactful styling suggestion for a {gender} individual with a {body_type} body "
|
| 8 |
+
"and {face_shape} face attending the {occasion}. They have on {items}. "
|
| 9 |
+
"Highlight a strategic enhancement in silhouette, color scheme, accessory choice, or footwear to elevate their look."
|
| 10 |
+
),
|
| 11 |
+
"event_aesthetic": (
|
| 12 |
+
"Imagine you are curating an immersive style experience for a {gender} attendee with a {body_type} silhouette and {face_shape} face at the {occasion}. "
|
| 13 |
+
"They’re currently wearing {items}. Provide one highly descriptive recommendation that harmonizes fabric textures, color temperature, silhouette, and accessory accents with the event’s specific ambiance, lighting conditions, and seasonal atmosphere."
|
| 14 |
+
),
|
| 15 |
+
"fashion_editor": (
|
| 16 |
+
"You are the Editor-in-Chief of a prestigious fashion publication. Advise a {gender} trendsetter with a {body_type} frame and {face_shape} face attending the {occasion}, "
|
| 17 |
+
"currently in {items}. Offer one magazine-cover-worthy styling tip—highlight a trending color palette, editorial-worthy silhouette, and innovative accessory placement that will resonate with a discerning audience."
|
| 18 |
+
),
|
| 19 |
+
"influencer_style": (
|
| 20 |
+
"As a cutting-edge style influencer with millions of followers, recommend one eye-catching flair tip for a {gender} follower with a {body_type} physique and {face_shape} face, "
|
| 21 |
+
"heading to the {occasion} in {items}. Frame it as a social-media-caption-ready moment: mention a statement accessory, bold color pop, or texture twist that will go viral."
|
| 22 |
+
),
|
| 23 |
+
"seasonal_trend": (
|
| 24 |
+
"As a seasonal style expert specializing in spring/summer trends, guide a {gender} individual with a {body_type} shape and {face_shape} face preparing for the {occasion}. "
|
| 25 |
+
"They currently wear {items}. Provide one tip incorporating current seasonal motifs—think floral prints, breathable linens, or eco-friendly fabrics—that elevates their ensemble."
|
| 26 |
+
),
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
class StyleSavvy:
|
| 30 |
+
def __init__(
|
| 31 |
+
self,
|
| 32 |
+
model_name: str = "google/flan-t5-large",
|
| 33 |
+
device: int = -1, # -1 = CPU, or GPU index
|
| 34 |
+
max_length: int = 150,
|
| 35 |
+
):
|
| 36 |
+
# A local instruction-tuned T5 model
|
| 37 |
+
self.pipe = pipeline(
|
| 38 |
+
"text2text-generation",
|
| 39 |
+
model=model_name,
|
| 40 |
+
tokenizer=model_name,
|
| 41 |
+
device=device,
|
| 42 |
+
)
|
| 43 |
+
self.max_length = max_length
|
| 44 |
+
self.num_beams = 4
|
| 45 |
+
# TODO: Modification: Add more prompts to the advise function
|
| 46 |
+
# to make it more specific to the user's needs.
|
| 47 |
+
# The function now takes in the user's body type, face shape, and occasion
|
| 48 |
+
# and generates style tips accordingly.
|
| 49 |
+
|
| 50 |
+
def advise(self,
|
| 51 |
+
items: List[str],
|
| 52 |
+
body_type: str,
|
| 53 |
+
face_shape: str,
|
| 54 |
+
gender: str,
|
| 55 |
+
occasion: str
|
| 56 |
+
) -> List[str]:
|
| 57 |
+
"""
|
| 58 |
+
Generate one result per prompt template and return all as a list.
|
| 59 |
+
"""
|
| 60 |
+
labels = ", ".join(items) if items else "an outfit"
|
| 61 |
+
results: List[str] = []
|
| 62 |
+
for tpl in PROMPTS.values():
|
| 63 |
+
prompt = tpl.format(
|
| 64 |
+
body_type=body_type,
|
| 65 |
+
face_shape=face_shape,
|
| 66 |
+
gender = gender,
|
| 67 |
+
occasion=occasion,
|
| 68 |
+
items=labels
|
| 69 |
+
)
|
| 70 |
+
out = self.pipe(
|
| 71 |
+
prompt,
|
| 72 |
+
max_length=self.max_length,
|
| 73 |
+
num_beams=self.num_beams,
|
| 74 |
+
early_stopping=True,
|
| 75 |
+
do_sample=False,
|
| 76 |
+
no_repeat_ngram_size=3, # avoid repeating phrases
|
| 77 |
+
)[0]["generated_text"].strip()
|
| 78 |
+
results.append(out)
|
| 79 |
+
return results
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
models/vision.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# models/vision.py -- Working
|
| 3 |
+
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
class VisionModel:
|
| 8 |
+
def __init__(
|
| 9 |
+
self,
|
| 10 |
+
model_name: str = "valentinafeve/yolos-fashionpedia",
|
| 11 |
+
threshold: float = 0.7
|
| 12 |
+
):
|
| 13 |
+
self.pipe = pipeline("object-detection", model=model_name)
|
| 14 |
+
self.threshold = threshold
|
| 15 |
+
|
| 16 |
+
def detect(self, image: Image.Image):
|
| 17 |
+
# 1) Ensure RGB
|
| 18 |
+
if image.mode != "RGB":
|
| 19 |
+
image = image.convert("RGB")
|
| 20 |
+
|
| 21 |
+
# 2) Run detection
|
| 22 |
+
results = self.pipe(image)
|
| 23 |
+
|
| 24 |
+
# 3) Process & filter
|
| 25 |
+
processed = []
|
| 26 |
+
for r in results:
|
| 27 |
+
score = float(r["score"])
|
| 28 |
+
if score < self.threshold:
|
| 29 |
+
continue
|
| 30 |
+
|
| 31 |
+
# r["box"] is a dict: {"xmin":..., "ymin":..., "xmax":..., "ymax":...}
|
| 32 |
+
box = r["box"]
|
| 33 |
+
coords = [
|
| 34 |
+
float(box["xmin"]),
|
| 35 |
+
float(box["ymin"]),
|
| 36 |
+
float(box["xmax"]),
|
| 37 |
+
float(box["ymax"]),
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
processed.append({
|
| 41 |
+
"label": r["label"],
|
| 42 |
+
"score": score,
|
| 43 |
+
"box": coords
|
| 44 |
+
})
|
| 45 |
+
|
| 46 |
+
return processed
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
utils.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d50e1f3884c180574825b8583b5807222caef442523680315924f44ba2ecac40
|
| 3 |
+
size 10368
|