Download test_handler.py from re-mind/aimv2-large-patch14-native-embedding-inference: direct link, hf CLI and curl.
- Browser
- Download file 764 Bytes
-
https://huggingface.co/re-mind/aimv2-large-patch14-native-embedding-inference/resolve/main/test_handler.py
- Command line
-
hf download hf://re-mind/aimv2-large-patch14-native-embedding-inference/test_handler.py
-
curl -L -o test_handler.py https://huggingface.co/re-mind/aimv2-large-patch14-native-embedding-inference/resolve/main/test_handler.py
764 Bytes
| 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) | |