Last active
May 4, 2022 05:24
-
-
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
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 | |
# 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']}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.