HTT / test_classification.py
Deep
backend
e7b5120
Raw
History Blame Contribute Delete
2.51 kB
"""
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)