Last active
October 13, 2025 00:27
-
-
Save symisc/fa917e43187a1ab4c5b4fb63b5b56fdc to your computer and use it in GitHub Desktop.
Generate image embeding vector for a given image using the PixLab image embedding API - https://pixlab.io/endpoints/img-embed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
# Generate image embedding vector for a given image using the PixLab image embedding API | |
# Refer to: https://pixlab.io/endpoints/img-embed for the official documentation. | |
# | |
# Convert images into numerical vectors for efficient image classification, similarity search, and so on. | |
# Target Image URL we want to generate embedding for | |
# Change to any link or switch to POST if you want to upload your image directly. | |
imgUrl = 'https://pixlab.io/assets/images/nature31.jpg' | |
key = 'PIXLAB_API_KEY' # Get your API key from https://console.pixlab.io/ | |
# Make the API call; Switch to POST if you want to upload your image directly. | |
req = requests.get('https://api.pixlab.io/imgembed',params={ | |
'img': imgUrl, | |
'key': key, | |
'dimension': 1024, # Output vector dimension | |
}) | |
reply = req.json() | |
if reply['status'] != 200: | |
print (reply['error']) | |
else: | |
embedding = reply['embedding'] | |
print(f"Image embedding vector: {embedding}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment