File size: 764 Bytes
ffbf25c |
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 |
import base64
from io import BytesIO
import requests
from PIL import Image
# Import the EndpointHandler class
from handler import EndpointHandler
# Fetch the image from the URL
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
response = requests.get(url, stream=True)
image = Image.open(response.raw).convert("RGB") # Ensure the image is in RGB format
# Encode the image as base64
buffered = BytesIO()
image.save(buffered, format="JPEG") # Save the image to a buffer in JPEG format
encoded_image = base64.b64encode(buffered.getvalue()).decode("utf-8")
# Prepare the input data
data = {"images": [encoded_image]}
# Initialize the handler
handler = EndpointHandler()
# Process the image
result = handler(data)
# Print the result
print(result)
|