| """ | |
| Test script for the HuggingFace Space API | |
| """ | |
| from gradio_client import Client | |
| import sys | |
| try: | |
| print("Connecting to HuggingFace Space...") | |
| client = Client("smartfalcon-ai/Industrial-Defect-Detection") | |
| print("[OK] Connected successfully!") | |
| print(f"\nSpace URL: {client.space_id}") | |
| # Test with a simple test - create a dummy image | |
| print("\nTesting API with test image...") | |
| import numpy as np | |
| from PIL import Image | |
| import io | |
| import base64 | |
| # Create a simple test image (640x640 RGB) | |
| test_img = np.random.randint(0, 255, (640, 640, 3), dtype=np.uint8) | |
| result = client.predict( | |
| test_img, | |
| "Data Matrix", | |
| 0.25, | |
| api_name="/predict" | |
| ) | |
| print("[OK] API call successful!") | |
| print(f"\nResult type: {type(result)}") | |
| print(f"Result: {result}") | |
| except Exception as e: | |
| print(f"[ERROR] {e}") | |
| sys.exit(1) | |