Skip to content

Instantly share code, notes, and snippets.

@symisc
Last active May 4, 2022 05:24
Show Gist options
  • Save symisc/5f0fe67ab0f370021293b0c839e432a8 to your computer and use it in GitHub Desktop.
Save symisc/5f0fe67ab0f370021293b0c839e432a8 to your computer and use it in GitHub Desktop.
Tag (Generate a description of) an image based on detected visual content using the PixLab API - https://pixlab.io/cmd?id=tagimg
import requests
import json
# Generates a description of an image in human readable language with complete sentences.
# The description is based on the visual content as reported by our state-of-the-art image labeling algorithm.
# More than one description can be generated for each image. Descriptions are ordered by their confidence score.
# https://pixlab.io/cmd?id=tagimg for the official documentation.
# Target Image: Change to any link or switch to POST if you want to upload your image directly, refer to the sample set for more info.
img = 'https://s-media-cache-ak0.pinimg.com/originals/35/d0/f6/35d0f6ee0e40306c41cfd714c625f78e.jpg'
# Your PixLab API Key. Get yours from https://console.pixlab.io/
key = 'PIXLAB_API_KEY'
req = requests.get('https://api.pixlab.io/tagimg',params={'img':img,'key':key})
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
else:
total = len(reply['tags']) # Total tags
print (f"Total extracted tags: {total}")
for tag in reply['tags']:
print(f"Tag Name: {tag['name']} - Confidence Score: {tag['confidence']}")
@symisc
Copy link
Author

symisc commented May 4, 2022

Generates a description of an image in human readable language with complete sentences.
The description is based on the visual content as reported by our state-of-the-art image labeling algorithm.
More than one description can be generated for each image. Descriptions are ordered by their confidence score.
https://pixlab.io/cmd?id=tagimg for the official documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment