Spaces:
Sleeping
Sleeping
#!/usr/bin/env python3 | |
""" | |
Demo script showing the enhanced fashion analysis capabilities | |
""" | |
import requests | |
import json | |
from pathlib import Path | |
def demo_enhanced_analysis(): | |
"""Demonstrate the enhanced analysis features""" | |
server_url = "http://localhost:7861" | |
print("π½ Enhanced Fashion Analysis Demo") | |
print("=" * 60) | |
# First, show the refined prompt | |
print("\nπ 1. Refined Prompt Structure") | |
print("-" * 40) | |
try: | |
response = requests.get(f"{server_url}/refined-prompt") | |
if response.status_code == 200: | |
prompt = response.text | |
# Show just the key sections | |
lines = prompt.split('\n') | |
for i, line in enumerate(lines): | |
if i < 50: # Show first 50 lines | |
print(line) | |
print("... (truncated for demo)") | |
else: | |
print(f"β Error getting prompt: {response.status_code}") | |
except Exception as e: | |
print(f"β Error: {e}") | |
print("\nπ 2. Analysis Capabilities") | |
print("-" * 40) | |
# Show the different endpoints available | |
endpoints = [ | |
("/analyze-enhanced", "Enhanced Prompt Analysis", "Advanced fashion analysis with detailed insights"), | |
("/analyze-structured", "Structured Analysis", "JSON format with structured data"), | |
("/analyze", "Basic Analysis", "Standard fashion analysis"), | |
("/detect-objects", "Object Detection", "Fashion item detection only"), | |
("/extract-features", "Feature Extraction", "Fashion feature vectors") | |
] | |
for endpoint, name, description in endpoints: | |
print(f"β’ {name}: {endpoint}") | |
print(f" {description}") | |
print("\nπ¨ 3. Enhanced Features") | |
print("-" * 40) | |
features = [ | |
"Fashion-specific vocabulary (oversized, tailored, cropped, monochromatic)", | |
"Color theory analysis (warm/cool tones, seasonal suitability)", | |
"Formality level inference (smart casual, athleisure, streetwear)", | |
"Fit and silhouette analysis (slim-fit, relaxed, boxy, flowy)", | |
"Material intelligence (texture, care, quality insights)", | |
"Comprehensive feature extraction with styling context", | |
"Professional outfit summaries with fashion expertise" | |
] | |
for feature in features: | |
print(f"β {feature}") | |
print("\nπ 4. Sample Analysis Structure") | |
print("-" * 40) | |
sample_analysis = """ | |
**UPPER GARMENT** | |
**Type**: Button-down chambray shirt | |
**Color**: Light denim blue (cool tone) with faded areas on collar and seams | |
**Material**: Chambray (lightweight woven cotton) | |
**Features**: Long sleeves rolled to elbows, pointed collar, front patch pockets, relaxed fit, visible stitching | |
--- | |
**LOWER GARMENT** | |
**Type**: Black slim-fit chinos | |
**Color**: Solid black (neutral tone) | |
**Material**: Stretch cotton twill | |
**Features**: Flat front, minimal pockets, cropped ankle length, clean silhouette | |
--- | |
**FOOTWEAR** | |
**Type**: White minimalist sneakers | |
**Color**: White with subtle grey accents on heel tab | |
**Material**: Leather upper with rubber sole | |
**Features**: Lace-up closure, low-profile design, round toe | |
--- | |
**OUTFIT SUMMARY** | |
This outfit channels effortless smart-casual style with its blend of soft textures and minimal structure. The chambray shirt introduces a laid-back, workwear-inspired vibe, complemented by the refined edge of slim black chinos. The white sneakers tie the look together with understated coolness, ensuring comfort without sacrificing polish. The color palette of light blue, black, and white reflects balance and neutrality, making the outfit adaptable for casual office settings, social outings, or relaxed dates. The overall silhouette is clean and streamlined, making it modern, versatile, and easy to accessorize. | |
""" | |
print(sample_analysis) | |
print("\nπ 5. Usage Instructions") | |
print("-" * 40) | |
usage_instructions = [ | |
"1. Start the server: python fast.py", | |
"2. Test with image: python test_enhanced_analysis.py your_image.jpg", | |
"3. Use API endpoint: POST /analyze-enhanced with image file", | |
"4. Compare methods: python test_enhanced_analysis.py image.jpg", | |
"5. Get refined prompt: GET /refined-prompt" | |
] | |
for instruction in usage_instructions: | |
print(instruction) | |
print("\nπ‘ 6. Benefits for Outfit Recommendation") | |
print("-" * 40) | |
benefits = [ | |
"Better feature extraction for recommendation algorithms", | |
"Style context understanding for occasion-based suggestions", | |
"Color harmony analysis for coordinated outfit building", | |
"Material awareness for fabric-appropriate styling", | |
"Professional-level fashion insights for quality recommendations" | |
] | |
for benefit in benefits: | |
print(f"β’ {benefit}") | |
print("\n" + "=" * 60) | |
print("π― Ready to test! Use the test script with your fashion images.") | |
print("=" * 60) | |
def check_server_status(): | |
"""Check if the server is running""" | |
server_url = "http://localhost:7861" | |
try: | |
response = requests.get(f"{server_url}/health") | |
if response.status_code == 200: | |
data = response.json() | |
print(f"β Server is running: {data}") | |
return True | |
else: | |
print(f"β Server health check failed: {response.status_code}") | |
return False | |
except requests.exceptions.ConnectionError: | |
print("β Server is not running. Start it with: python fast.py") | |
return False | |
except Exception as e: | |
print(f"β Error checking server: {e}") | |
return False | |
def main(): | |
"""Main demo function""" | |
print("π Checking server status...") | |
if check_server_status(): | |
print("\n") | |
demo_enhanced_analysis() | |
else: | |
print("\nπ To start the demo:") | |
print("1. Run: python fast.py") | |
print("2. Wait for server to start") | |
print("3. Run: python demo_enhanced_analysis.py") | |
if __name__ == "__main__": | |
main() | |