Spaces:
Sleeping
Sleeping
| #!/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'}") | |