File size: 2,509 Bytes
e7b5120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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)