Skip to content

Commit 97900ef

Browse files
committed
Merge pull request AlchemyAPI#14 from hugadams/master
FaceTagging - Thanks!
2 parents 79f955e + 026c982 commit 97900ef

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

alchemyapi.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class AlchemyAPI:
123123
ENDPOINTS['imagetagging'] = {}
124124
ENDPOINTS['imagetagging']['url'] = '/url/URLGetRankedImageKeywords'
125125
ENDPOINTS['imagetagging']['image'] = '/image/ImageGetRankedImageKeywords'
126+
ENDPOINTS['facetagging'] = {}
127+
ENDPOINTS['facetagging']['url'] = '/url/URLGetRankedImageFaceTags'
128+
ENDPOINTS['facetagging']['image'] = '/image/ImageGetRankedImageFaceTags'
126129
ENDPOINTS['taxonomy'] = {}
127130
ENDPOINTS['taxonomy']['url'] = '/url/URLGetRankedTaxonomy'
128131
ENDPOINTS['taxonomy']['html'] = '/html/HTMLGetRankedTaxonomy'
@@ -720,6 +723,24 @@ def imageTagging(self, flavor, data, options={}):
720723
options[flavor] = data
721724
return self.__analyze(AlchemyAPI.ENDPOINTS['imagetagging'][flavor], {}, options)
722725

726+
def faceTagging(self, flavor, data, options={}):
727+
"""
728+
729+
INPUT:
730+
flavor -> which version of the call only url or image.
731+
data -> the data to analyze, either the the url or path to image.
732+
options -> various parameters that can be used to adjust how the API works, see below for more info on the available options.
733+
"""
734+
if flavor not in AlchemyAPI.ENDPOINTS['facetagging']:
735+
return {'status': 'ERROR', 'statusInfo': 'facetagging for ' + flavor + ' not available'}
736+
elif 'image' == flavor:
737+
image = open(data, 'rb').read()
738+
options['imagePostMode'] = 'raw'
739+
return self.__analyze(AlchemyAPI.ENDPOINTS['facetagging'][flavor], options, image)
740+
741+
options[flavor] = data
742+
return self.__analyze(AlchemyAPI.ENDPOINTS['facetagging'][flavor], {}, options)
743+
723744
def __analyze(self, endpoint, params, post_data=bytearray()):
724745
"""
725746
HTTP Request wrapper that is called by the endpoint functions. This function is not intended to be called through an external interface.

0 commit comments

Comments
 (0)