import requests import os import glob api_url = "https://maftuh-main-batik-classifier.hf.space/predict" dataset_dir = r"C:\Users\muhammadmaftuh\warisan-digital\ml-service\dataset_batik" # Test different batik types test_classes = ["batik-parang", "batik-kawung", "batik-megamendung", "batik-ceplok", "batik-lasem"] print("\n" + "="*70) print(" TESTING BATIK CLASSIFIER WITH MULTIPLE PATTERNS") print("="*70) correct = 0 total = 0 for batik_class in test_classes: class_dir = os.path.join(dataset_dir, batik_class) images = glob.glob(os.path.join(class_dir, "*.jpg"))[:1] # Test 1 image per class for image_path in images: total += 1 print(f"\n Testing: {batik_class}") print(f" File: {os.path.basename(image_path)}") try: with open(image_path, 'rb') as f: files = {'image': (os.path.basename(image_path), f, 'image/jpeg')} response = requests.post(api_url, files=files, timeout=30) if response.status_code == 200: result = response.json() top_pred = result['predictions'][0] confidence = top_pred['confidence'] * 100 is_correct = top_pred['class'] == batik_class if is_correct: correct += 1 print(f" Predicted: {top_pred['class']} ({confidence:.1f}%)") else: print(f" Predicted: {top_pred['class']} ({confidence:.1f}%)") print(f" Expected: {batik_class}") else: print(f" Error: {response.status_code}") except Exception as e: print(f" Exception: {e}") print("\n" + "="*70) print(f" RESULTS: {correct}/{total} correct ({correct/total*100:.1f}%)") print("="*70)