Spaces:
Build error
Build error
| 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() |