File size: 1,338 Bytes
af1d8cd | 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 | from services.classifier import classify_garment
import requests
import os
import shutil
def test_robustness():
print("Testing Classifier Robustness...")
# 1. Test with "Jeans.jpg" (Should be Bottom via Fallback if API fails)
img_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Jeans.jpg/440px-Jeans.jpg"
filename = "Jeans.jpg" # Capitalized to test case insensitivity
with open(filename, "wb") as f:
f.write(requests.get(img_url).content)
print(f"\n1. input: {filename}")
cat, desc, tags = classify_garment(filename)
print(f" -> Result: Category={cat}, Desc={desc}, Source={tags}")
if cat == "bottom":
print("✅ SUCCESS: Detected matching bottom (Logic Works)")
else:
print("❌ FAILURE: Did not detect bottom")
# 2. Test with "black_tshirt.jpg" (Should be Top)
filename2 = "black_tshirt.jpg"
shutil.copy(filename, filename2) # Just copy content, name matters
print(f"\n2. input: {filename2}")
cat, desc, tags = classify_garment(filename2)
print(f" -> Result: Category={cat}, Desc={desc}, Source={tags}")
if cat == "top":
print("✅ SUCCESS: Detected matching top")
else:
print("❌ FAILURE: Failed top detection")
if __name__ == "__main__":
test_robustness()
|