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) | |