Spaces:
Sleeping
Sleeping
| """ | |
| Quick test script for product classification service | |
| Upload any product image to test the Gemini AI classification | |
| """ | |
| import requests | |
| import sys | |
| # API endpoint | |
| API_URL = "http://localhost:8000/api/inference/" | |
| def test_classification(image_path): | |
| """Test the classification endpoint with an image""" | |
| print(f"Testing classification with image: {image_path}") | |
| print("-" * 50) | |
| try: | |
| # Open and send the image | |
| with open(image_path, 'rb') as image_file: | |
| files = {'image': image_file} | |
| response = requests.post(API_URL, files=files) | |
| # Check response | |
| if response.status_code == 200: | |
| result = response.json() | |
| classification = result.get('status', 'unknown') | |
| print(f"β SUCCESS!") | |
| print(f"Classification: {classification.upper()}") | |
| print(f"Raw response: {result}") | |
| print("-" * 50) | |
| # Interpretation | |
| if classification == 'resellable': | |
| print("π’ Product is in excellent condition - can be resold as-is") | |
| elif classification == 'refurb': | |
| print("π‘ Product needs refurbishment - minor repairs needed") | |
| elif classification == 'scrap': | |
| print("π΄ Product is damaged beyond repair - must be scrapped") | |
| else: | |
| print(f"β ERROR: Status code {response.status_code}") | |
| print(f"Response: {response.text}") | |
| except FileNotFoundError: | |
| print(f"β ERROR: Image file not found: {image_path}") | |
| print("Please provide a valid image path") | |
| except requests.exceptions.ConnectionError: | |
| print("β ERROR: Cannot connect to the backend server") | |
| print("Make sure Django server is running on http://localhost:8000") | |
| except Exception as e: | |
| print(f"β ERROR: {str(e)}") | |
| if __name__ == "__main__": | |
| if len(sys.argv) < 2: | |
| print("Usage: python test_classification.py <image_path>") | |
| print("\nExample:") | |
| print(" python test_classification.py sample_product.jpg") | |
| print("\nTest with different product conditions:") | |
| print(" - New/pristine product β should return 'resellable'") | |
| print(" - Scratched/damaged product β should return 'refurb'") | |
| print(" - Broken/destroyed product β should return 'scrap'") | |
| sys.exit(1) | |
| image_path = sys.argv[1] | |
| test_classification(image_path) | |