zorba111/ui-coordinates-finder
0
1import requests2from PIL import Image3import base644import io5 6def test_api():7 url = "https://zorba11--ui-coordinates-finder-fastapi-app.modal.run/process"8 9 # Parameters matching your Gradio demo10 params = {11 'box_threshold': 0.05,12 'iou_threshold': 0.1,13 'screen_width': 1920,14 'screen_height': 108015 }16 17 files = {18 'file': ('screen-1.png', open('/Users/zorba11/Desktop/screen-1.png', 'rb'), 'image/png')19 }20 21 response = requests.post(url, files=files, params=params)22 23 if response.status_code == 200:24 result = response.json()25 26 # Convert base64 image back to PIL Image27 img_data = base64.b64decode(result['processed_image'])28 processed_image = Image.open(io.BytesIO(img_data))29 30 # Save the processed image31 processed_image.save('processed_output.png')32 33 # Print the detected elements34 for element in result['elements']:35 print("\nElement:", element['description'])36 print("Normalized coordinates:", element['normalized_coords'])37 print("Screen coordinates:", element['screen_coords'])38 print("Dimensions:", element['dimensions'])39 else:40 print("Error:", response.text)41 42if __name__ == "__main__":43 test_api() 