Spaces:
Sleeping
Sleeping
| import requests | |
| import os | |
| # Test configuration | |
| image_path = r"C:\Users\muhammadmaftuh\warisan-digital\ml-service\dataset_batik\batik-parang\1.jpg" | |
| api_url = "https://maftuh-main-batik-classifier.hf.space/predict" | |
| print("\n Testing Batik Classifier API") | |
| print(f"Image: batik-parang\\1.jpg (Expected: batik-parang)\n") | |
| print(" Sending request to API...") | |
| # Send prediction request | |
| with open(image_path, 'rb') as f: | |
| files = {'image': ('test.jpg', f, 'image/jpeg')} | |
| response = requests.post(api_url, files=files) | |
| if response.status_code == 200: | |
| result = response.json() | |
| print("\n Prediction successful!\n") | |
| print(" Top 5 Predictions:") | |
| print("=" * 60) | |
| for i, pred in enumerate(result['predictions'], 1): | |
| confidence = pred['confidence'] * 100 | |
| bar = "" * int(confidence / 2) | |
| color = "\033[92m" if i == 1 and confidence > 50 else "\033[0m" | |
| print(f"{color} {i}. {pred['class']:<22} {confidence:.2f}% {bar}\033[0m") | |
| print(f"\n Model: {result['model']}") | |
| print(f" Accuracy: {result['accuracy'] * 100:.1f}%") | |
| else: | |
| print(f"\n Error: {response.status_code}") | |
| print(f"Response: {response.text}") | |