Spaces:
Sleeping
Sleeping
File size: 3,236 Bytes
1daba48 |
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 |
#!/usr/bin/env python3
"""
Test script to verify the improved image classification
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from app.pipeline import classify_report
def test_park_water_classification():
"""Test park filled with water classification"""
print("Testing park filled with water classification...")
report = {
"report_id": "test_park_001",
"description": "park is filled with water in this location",
"category": "Parks & Recreation",
"user_id": "test_user",
"image_url": "https://example.com/park_water.jpg"
}
result = classify_report(report)
print(f"Result: {result}")
if result["status"] == "accepted":
print("β
Park water classification PASSED")
else:
print(f"β Park water classification FAILED: {result.get('reason', 'Unknown reason')}")
return result["status"] == "accepted"
def test_streetlight_classification():
"""Test streetlight classification"""
print("\nTesting streetlight classification...")
report = {
"report_id": "test_light_001",
"description": "street light is not working in this location",
"category": "Street Lighting",
"user_id": "test_user",
"image_url": "https://example.com/streetlight.jpg"
}
result = classify_report(report)
print(f"Result: {result}")
if result["status"] == "accepted":
print("β
Streetlight classification PASSED")
else:
print(f"β Streetlight classification FAILED: {result.get('reason', 'Unknown reason')}")
return result["status"] == "accepted"
def test_without_image():
"""Test classification without image (should rely on text)"""
print("\nTesting without image (text-only classification)...")
report = {
"report_id": "test_text_001",
"description": "park is filled with water in this location",
"category": "Parks & Recreation",
"user_id": "test_user",
"image_url": None
}
result = classify_report(report)
print(f"Result: {result}")
if result["status"] == "accepted":
print("β
Text-only classification PASSED")
else:
print(f"β Text-only classification FAILED: {result.get('reason', 'Unknown reason')}")
return result["status"] == "accepted"
if __name__ == "__main__":
print("π§ͺ Testing improved image classification...")
print("=" * 50)
# Run tests
park_test = test_park_water_classification()
light_test = test_streetlight_classification()
text_test = test_without_image()
print("\n" + "=" * 50)
print("π Test Results:")
print(f"Park water classification: {'β
PASSED' if park_test else 'β FAILED'}")
print(f"Streetlight classification: {'β
PASSED' if light_test else 'β FAILED'}")
print(f"Text-only classification: {'β
PASSED' if text_test else 'β FAILED'}")
all_passed = park_test and light_test and text_test
print(f"\nOverall: {'β
ALL TESTS PASSED' if all_passed else 'β SOME TESTS FAILED'}")
|