File size: 3,734 Bytes
d6e97b5 |
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 |
import requests
import time
def test_proper_api():
"""Test the proper API with comprehensive evaluation"""
test_scenes = [
"A car driving through a city at night with neon lights",
"A person dancing in a room with colorful lighting effects",
"A mountain landscape with sunset and trees",
"A modern building with glass windows reflecting sunlight"
]
print("π§ͺ TESTING PROPER API - COMPREHENSIVE EVALUATION")
print("=" * 65)
for scene in test_scenes:
try:
start_time = time.time()
response = requests.post(
"http://localhost:8006/describe/scene",
json={
"scene_description": scene,
"enhance_adjectives": True
},
timeout=10
)
processing_time = (time.time() - start_time) * 1000
if response.status_code == 200:
result = response.json()
output = result["enhanced_description"]
print(f"π INPUT: {scene}")
print(f"π OUTPUT: {output}")
print(f"β‘ TIME: {processing_time:.2f}ms")
# Quality metrics
words = output.split()
adjective_count = self.count_adjectives(output)
sentence_quality = self.assess_sentence_quality(output)
print(f"π METRICS: {len(words)} words, {adjective_count} adjectives")
print(f"π― QUALITY: {sentence_quality}")
print("β" * 65)
else:
print(f"β FAILED: {scene}")
print("β" * 65)
except Exception as e:
print(f"π₯ ERROR: {e}")
print("β" * 65)
def count_adjectives(self, text):
"""Count quality adjectives in text"""
quality_adjectives = [
'sleek', 'modern', 'gleaming', 'luxurious', 'sporty', 'vibrant',
'bustling', 'illuminated', 'colorful', 'glowing', 'dazzling',
'energetic', 'graceful', 'expressive', 'charismatic', 'dynamic',
'atmospheric', 'majestic', 'towering', 'snow-capped', 'rugged',
'breathtaking', 'dramatic', 'picturesque', 'stunning', 'lush',
'verdant', 'imposing', 'architectural', 'reflective', 'shimmering',
'golden', 'warm', 'brilliant', 'radiant'
]
text_lower = text.lower()
return sum(1 for adj in quality_adjectives if adj in text_lower)
def assess_sentence_quality(self, text):
"""Assess basic sentence quality"""
if not text:
return "Poor: Empty output"
# Check for proper sentence structure
has_capital = text[0].isupper() if text else False
has_period = text.endswith('.') if text else False
word_count = len(text.split())
# Check for common issues
issues = []
if not has_capital:
issues.append("no capitalization")
if not has_period:
issues.append("no ending punctuation")
if word_count < 3:
issues.append("too short")
if word_count > 25:
issues.append("too long")
if ' .' in text or ' ,' in text:
issues.append("spacing before punctuation")
if not issues:
return "Excellent: Proper structure"
elif len(issues) == 1:
return f"Good: Minor issue ({issues[0]})"
else:
return f"Needs work: {', '.join(issues)}"
if __name__ == "__main__":
test_proper_api()
|