File size: 760 Bytes
f9c9a7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)