File size: 1,326 Bytes
36a599e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import requests
from PIL import Image
import base64
import io

def test_api():
    url = "https://zorba11--ui-coordinates-finder-fastapi-app.modal.run/process"
    
    # Parameters matching your Gradio demo
    params = {
        'box_threshold': 0.05,
        'iou_threshold': 0.1,
        'screen_width': 1920,
        'screen_height': 1080
    }
    
    files = {
        'file': ('screen-1.png', open('/Users/zorba11/Desktop/screen-1.png', 'rb'), 'image/png')
    }
    
    response = requests.post(url, files=files, params=params)
    
    if response.status_code == 200:
        result = response.json()
        
        # Convert base64 image back to PIL Image
        img_data = base64.b64decode(result['processed_image'])
        processed_image = Image.open(io.BytesIO(img_data))
        
        # Save the processed image
        processed_image.save('processed_output.png')
        
        # Print the detected elements
        for element in result['elements']:
            print("\nElement:", element['description'])
            print("Normalized coordinates:", element['normalized_coords'])
            print("Screen coordinates:", element['screen_coords'])
            print("Dimensions:", element['dimensions'])
    else:
        print("Error:", response.text)

if __name__ == "__main__":
    test_api()