Friday, November 18, 2016

Clarifai Python API in Python

#####################################
## Change Models
#####################################
from clarifai.rest import ClarifaiApp

app = ClarifaiApp()

# General
#model = app.models.get('general-v1.3')

# NSFW
#model = app.models.get('nsfw-v1.0')

# Weddings
#model = app.models.get('weddings-v1.0')

# Travel
#model = app.models.get('travel-v1.0')

# Food
#model = app.models.get('food-items-v1.0')

# for key in result.keys():
# print key
#model.get_concept_ids()
returndat=result['outputs'][0]['data']['concepts']
#print len(returndat)
for key in returndat:
print key['name']


#####################################
## Tag Models
#####################################
from clarifai.rest import ClarifaiApp

app = ClarifaiApi(app_id = 'DjDv9k4c3un1LzCGNSC9USP_aKw1B5gf8DGcEz7a', app_secret = 'TtjTRjoluIbxFgGU8V6yGiiY5anAUqiJcXEPMSZp')
app.get_info()

# model = app.models.get('general-v1.3')

 # tag image from online URL
# result=model.tag_images('https://samples.clarifai.com/metro-north.jpg')
result=app.tag_image_urls('http://media.kohlsimg.com/is/image/kohls/1456134_Berry_Blossom?wid=360&hei=360&op_sharpen=1')

#for key in result.keys():
returnlist = result['outputs']
#for i in len(result['outputs']):
# print result['outputs']
returndict=result['outputs'][0]
returndat=result['outputs'][0]['data']['concepts']



from clarifai.client import ClarifaiApi, ApiError
 image_url = 'http://clarifai-img.s3.amazonaws.com/test/toddler-flowers.jpeg'
 api = ClarifaiApi()
 response = api.tag_image_urls(image_url)

No comments:

Post a Comment

Blog Archive