Spaces:
Running
Running
File size: 6,649 Bytes
10d8299 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# # test_llm.py
# """
# Test harness for StyleSavvy LLM prompts.
# Defines multiple prompt templates and evaluates the generated outputs,
# checking for the expected number of bullet-point style tips.
# """
# from models.llm import StyleSavvy
# # Variant prompt templates with placeholders
# PROMPT_TEMPLATES = {
# "occasion_driven": (
# "You are an expert fashion stylist. A client is preparing for {occasion}. "
# "They have a {body_type}-shaped body and a {face_shape} face. They’re currently wearing: {items}. "
# "Give 3 to 5 *distinct* style tips focused on making them look their best at the event. "
# "Make the suggestions relevant to the setting, weather, and formality of the occasion. "
# "Avoid repeating any advice."
# ),
# "function_based": (
# "You're advising someone with a {body_type} build and {face_shape} face. "
# "They're attending a {occasion} and are wearing {items}. "
# "Suggest 3–5 concise fashion improvements or enhancements. "
# "Each suggestion should be unique and tailored to the event. "
# "Include practical choices for color, layering, accessories, or footwear. "
# "Avoid repeating words or phrases."
# ),
# "intent_style": (
# "Act as a high-end personal stylist. Your client has a {body_type} body shape and a {face_shape} face. "
# "They're going to a {occasion} and are wearing {items}. "
# "Write 3 to 5 brief but powerful styling suggestions to elevate their look. "
# "Focus on intent—what feeling or impression each style choice creates for the event."
# ),
# }
# # Test parameters
# BODY_TYPE = "Slim"
# FACE_SHAPE = "Round"
# OCCASION = "Rooftop Evening Party"
# ITEMS = ["shirt", "jeans", "jacket","shoes"]
# if __name__ == "__main__":
# advisor = StyleSavvy()
# for name, template in PROMPT_TEMPLATES.items():
# # Build prompt by replacing placeholders
# prompt = template.format(
# body_type=BODY_TYPE,
# face_shape=FACE_SHAPE,
# occasion=OCCASION,
# items=", ".join(ITEMS)
# )
# print(f"=== Testing template: {name} ===")
# print("Prompt:")
# print(prompt)
# # Generate output (use only supported args)
# result = advisor.pipe(
# prompt,
# max_length=advisor.max_length,
# early_stopping=True,
# do_sample=False
# )[0]["generated_text"].strip()
# print("Generated output:")
# print(result)
# # Extract bullet lines
# bullets = [ln for ln in result.splitlines() if ln.strip().startswith("- ")]
# print(f"Number of bullets detected: {len(bullets)}")
# for i, b in enumerate(bullets, start=1):
# print(f" {i}. {b}")
# print("" + "-"*40)
# test_llm.py
"""
Test harness for StyleSavvy LLM prompts.
Evaluates multiple prompt templates and parses the generated outputs into distinct tips.
"""
from models.llm import StyleSavvy
# Variant prompt templates with placeholders
PROMPT_TEMPLATES = {
"direct_instruction": (
"You are a professional fashion stylist. A client with a {body_type} body shape "
"and {face_shape} face is preparing for a {occasion}. They are currently wearing {items}. "
"Give exactly five different styling tips to improve their outfit. "
"Each tip should be concise, actionable, and relevant to the event. Start each tip on a new line."
),
"category_expansion": (
"As a high-end fashion advisor, provide five styling tips for a {body_type}-shaped person "
"with a {face_shape} face attending a {occasion}. They are currently wearing {items}. "
"Offer one tip for each of the following categories: silhouette, color, accessories, footwear, and layering. "
"Each tip must be brief, specific, and clearly separated by a line break."
),
"event_aesthetic": (
"Imagine you're curating a perfect outfit for a {body_type}-shaped individual with a {face_shape} face "
"attending {occasion}. They are wearing {items}. Suggest 5 ways to enhance their style, focusing on event-appropriate aesthetics. "
"Write each tip as a separate sentence on a new line. Do not repeat advice or themes."
),
"fashion_editor": (
"As a fashion editor writing for a style magazine, outline five unique styling tips for a {body_type}-shaped reader "
"with a {face_shape} face who is attending {occasion}. They currently wear {items}. "
"Each recommendation should reflect expertise, relevance to the occasion, and a unique style element. "
"Deliver all five tips in a list format, starting each on a new line."
),
"influencer_style": (
"You’re an influencer known for your sharp styling advice. One of your followers has a {body_type} body and "
"{face_shape} face, and they're attending {occasion}. They’ve sent you a photo wearing {items}. "
"Reply with exactly five snappy, modern style tips they can use to upgrade their outfit for the event. "
"Make sure each tip is short, non-repetitive, and on its own line."
),
}
# Test parameters
BODY_TYPE = "Slim"
FACE_SHAPE = "Round"
OCCASION = "Rooftop Evening Party"
ITEMS = ["jeans", "jacket", "shoes"]
if __name__ == "__main__":
advisor = StyleSavvy()
for name, template in PROMPT_TEMPLATES.items():
print(f"=== Testing template: {name} ===")
# Build prompt
prompt = template.format(
body_type=BODY_TYPE,
face_shape=FACE_SHAPE,
occasion=OCCASION,
items=", ".join(ITEMS)
)
print("Prompt:\n" + prompt)
# Generate response
result = advisor.pipe(
prompt,
max_length=advisor.max_length,
early_stopping=True,
num_beams=4,
no_repeat_ngram_size=3,
do_sample=False)[0]["generated_text"].strip()
print("\nRaw generated output:\n" + result)
# Parse into tips (bullets or sentence)
lines = result.splitlines()
tips = [ln.strip("-*0123456789. ").strip() for ln in lines if ln.strip()]
if len(tips) < 3:
# fallback to sentence split
tips = [p.strip() for p in result.split(".") if p.strip()]
tips = list(dict.fromkeys(tips)) # remove duplicates
print(f"\n💡 Parsed {len(tips)} style tips:")
for i, tip in enumerate(tips[:5], 1):
print(f"{i}. {tip}")
print("-" * 40)
|