Spaces:
Sleeping
Sleeping
| import requests | |
| import json | |
| def test_dirty_data(): | |
| url = "http://localhost:8000/predict" | |
| # Test cases: | |
| # 1. Missing fields (should be handled by Pydantic validation) | |
| # 2. Null/None values (if allowed by Pydantic) | |
| # 3. Unknown categorical values (should be handled by OneHotEncoder handle_unknown='ignore') | |
| # 4. Out of range numerical values | |
| test_cases = [ | |
| { | |
| "name": "Unknown Categorical Values", | |
| "payload": { | |
| "City": "Mars city", | |
| "Neighborhood": "Alien Quarter", | |
| "Type": "Spaceship", | |
| "Surface": 5000.0, | |
| "Rooms": 100, | |
| "Bedrooms": 50, | |
| "Standing": "Galactic", | |
| "Residency": "Moon Base", | |
| "Orientation": "Vertical", | |
| "View": "Earth View", | |
| "Condition": "Futuristic", | |
| "Floor": -5, | |
| "Lift": 1, | |
| "Pool": 1, | |
| "Garden": 1, | |
| "Parking_Spots": 100, | |
| "Proximity_Tram": 0, | |
| "Proximity_University": 0, | |
| "Proximity_Mosque": 0 | |
| } | |
| }, | |
| { | |
| "name": "Extreme Numerical Values", | |
| "payload": { | |
| "City": "Casablanca", | |
| "Neighborhood": "Anfa", | |
| "Type": "Appartement", | |
| "Surface": 999999.0, | |
| "Rooms": 0, | |
| "Bedrooms": -1, | |
| "Standing": "Economique", | |
| "Residency": "Public / Quartier ouvert", | |
| "Orientation": "Nord", | |
| "View": "Vue sur rue", | |
| "Condition": "A rénover", | |
| "Floor": 999, | |
| "Lift": 0, | |
| "Pool": 0, | |
| "Garden": 0, | |
| "Parking_Spots": 0, | |
| "Proximity_Tram": 0, | |
| "Proximity_University": 0, | |
| "Proximity_Mosque": 0 | |
| } | |
| } | |
| ] | |
| for case in test_cases: | |
| print(f"\n--- Testing: {case['name']} ---") | |
| try: | |
| response = requests.post(url, json=case['payload']) | |
| print(f"Status: {response.status_code}") | |
| if response.status_code == 200: | |
| result = response.json() | |
| print(f"Prediction: {result.get('estimated_price')} {result.get('currency')}") | |
| print(f"AI Analysis: {result.get('ai_analysis')}") | |
| else: | |
| print(f"Error: {response.text}") | |
| except Exception as e: | |
| print(f"Connection error: {e}") | |
| if __name__ == "__main__": | |
| test_dirty_data() | |