Spaces:
Sleeping
Sleeping
File size: 4,405 Bytes
bb71884 |
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 |
#!/usr/bin/env python3
"""
Test script for the enhanced fashion analysis with refined prompt
"""
import requests
import json
import sys
from pathlib import Path
def test_enhanced_analysis(image_path, server_url="http://localhost:7861"):
"""Test the enhanced analysis endpoint"""
if not Path(image_path).exists():
print(f"Error: Image file {image_path} not found")
return
# Test the enhanced analysis endpoint
print("π Testing Enhanced Fashion Analysis")
print("=" * 50)
try:
with open(image_path, 'rb') as f:
files = {'file': f}
response = requests.post(f"{server_url}/analyze-enhanced", files=files)
if response.status_code == 200:
print("β
Enhanced Analysis Results:")
print("-" * 30)
print(response.text)
print("-" * 30)
else:
print(f"β Error: {response.status_code} - {response.text}")
except requests.exceptions.ConnectionError:
print(f"β Error: Could not connect to server at {server_url}")
print("Make sure the FastAPI server is running with: python fast.py")
except Exception as e:
print(f"β Error: {str(e)}")
def compare_analysis_methods(image_path, server_url="http://localhost:7861"):
"""Compare different analysis methods"""
if not Path(image_path).exists():
print(f"Error: Image file {image_path} not found")
return
print("π Comparing Analysis Methods")
print("=" * 50)
endpoints = [
("/analyze-enhanced", "Enhanced Prompt Analysis"),
("/analyze-structured", "Structured Analysis"),
("/analyze", "Basic Analysis")
]
for endpoint, name in endpoints:
print(f"\nπ {name}")
print("-" * 30)
try:
with open(image_path, 'rb') as f:
files = {'file': f}
response = requests.post(f"{server_url}{endpoint}", files=files)
if response.status_code == 200:
if endpoint == "/analyze-structured":
# This returns JSON
try:
data = response.json()
print(json.dumps(data, indent=2))
except:
print(response.text)
else:
print(response.text)
else:
print(f"β Error: {response.status_code} - {response.text}")
except requests.exceptions.ConnectionError:
print(f"β Error: Could not connect to server at {server_url}")
break
except Exception as e:
print(f"β Error: {str(e)}")
def test_refined_prompt(server_url="http://localhost:7861"):
"""Test the refined prompt endpoint"""
print("π Testing Refined Prompt")
print("=" * 50)
try:
response = requests.get(f"{server_url}/refined-prompt")
if response.status_code == 200:
print("β
Refined Prompt:")
print("-" * 30)
print(response.text)
print("-" * 30)
else:
print(f"β Error: {response.status_code} - {response.text}")
except requests.exceptions.ConnectionError:
print(f"β Error: Could not connect to server at {server_url}")
except Exception as e:
print(f"β Error: {str(e)}")
def main():
"""Main function"""
if len(sys.argv) < 2:
print("Usage: python test_enhanced_analysis.py <image_path> [server_url]")
print("Example: python test_enhanced_analysis.py test_image.jpg")
print("Example: python test_enhanced_analysis.py test_image.jpg http://localhost:7861")
return
image_path = sys.argv[1]
server_url = sys.argv[2] if len(sys.argv) > 2 else "http://localhost:7861"
print("π½ Enhanced Fashion Analysis Test")
print("=" * 50)
print(f"Image: {image_path}")
print(f"Server: {server_url}")
print("=" * 50)
# Test the refined prompt first
test_refined_prompt(server_url)
print("\n")
# Test enhanced analysis
test_enhanced_analysis(image_path, server_url)
print("\n")
# Compare all methods
compare_analysis_methods(image_path, server_url)
if __name__ == "__main__":
main()
|