Actionsync / minimal_test.py
barathvasan-dev
Fix: Parse HF Space detection response format correctly - handle single detection object not array
f9c9a7c
Raw
History Blame Contribute Delete
760 Bytes
import sys
import json
import tempfile
import os
from PIL import Image
from gradio_client import Client, handle_file
# Create a dummy image
img = Image.new("RGB", (640, 480), color=(73, 109, 137))
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmp:
img.save(tmp.name)
tmp_path = tmp.name
try:
print(f"Connecting to BARATH0070/plate-detector...")
client = Client("BARATH0070/plate-detector")
print(f"Calling /detect_and_save...")
result = client.predict(handle_file(tmp_path), api_name="/detect_and_save")
print("RESULT_START")
print(json.dumps(result, indent=2))
print("RESULT_END")
except Exception as e:
print(f"Error: {e}")
finally:
if os.path.exists(tmp_path):
os.remove(tmp_path)