当前位置: 首页>>代码示例>>Python>>正文


Python rest.ClarifaiApp方法代码示例

本文整理汇总了Python中clarifai.rest.ClarifaiApp方法的典型用法代码示例。如果您正苦于以下问题:Python rest.ClarifaiApp方法的具体用法?Python rest.ClarifaiApp怎么用?Python rest.ClarifaiApp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在clarifai.rest的用法示例。


在下文中一共展示了rest.ClarifaiApp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: img_has_cat

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def img_has_cat(filename):
    app = ClarifaiApp(api_key=settings.CLARIFAI_API_KEY)
    model = app.models.get("general-v1.3")
    try:
        image = Image(file_obj=open(filename, 'rb'))
        result = model.predict([image])
        try:
            items = result['outputs'][0]['data']['concepts']
            for item in items:
                if item['name'] == 'cat':
                    return True
            else:
                return False
        except (IndexError):
            return False
    except (client.ApiError, FileNotFoundError):
        return False 
开发者ID:korneevm,项目名称:simplebot,代码行数:19,代码来源:cat_checker.py

示例2: check_image

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def check_image(browser, clarifai_api_key, img_tags, logger, full_match=False):
    """Uses the link to the image to check for invalid content in the image"""
    clarifai_api = ClarifaiApp(api_key=clarifai_api_key)

    img_link = get_imagelink(browser)
    # Uses Clarifai's v2 API
    model = clarifai_api.models.get('general-v1.3')
    image = ClImage(url=img_link)
    result = model.predict([image])
    clarifai_tags = [concept.get('name').lower() for concept in result[
        'outputs'][0]['data']['concepts']]

    for (tags, should_comment, comments) in img_tags:
        if should_comment:
            if given_tags_in_result(tags, clarifai_tags, full_match):
                return True, comments
        else:
            if given_tags_in_result(tags, clarifai_tags, full_match):
                logger.info('Not Commenting, Possibly contains: "{}".'.format(', '.join(list(set(clarifai_tags)&set(tags)))))
                return False, []

    return True, [] 
开发者ID:timgrossmann,项目名称:InstaPy,代码行数:24,代码来源:clarifai_util.py

示例3: checkPhoto

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def checkPhoto(pictureURL, tag):
	resp = twiml.Response()
	photoApp = ClarifaiApp()
	#all concepts attached to the item specified in photo database (i.e. answer key)
	conceptGoals = [str(x) for x in mongo.db.photoGoals.find_one({"item":tag})["concepts"]]
	model = photoApp.models.get(tag)
	image = ClImage(url = pictureURL)
	#all data associated with each concept: id, name, appid, and value
	predictionData = json.loads(str(model.predict([image])))['outputs']['data']['concepts']
	userConcepts = []
	for x in predictionData:
		userConcepts.append(x[1])
	#all concepts included in user's photo
	conceptsPresent = conceptGoals.intersection(userConcepts)
	numbers = []
	for x in conceptsPresent:
		#threshold for approval is 51%
		probability = predictionData["value"]
		if probability > 0.5:
			numbers.append(probability)
	if numbers.length > 0:
		return True
	else:
		return False 
开发者ID:sara,项目名称:PhotoHunt,代码行数:26,代码来源:views.py

示例4: add_category

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def add_category(post):
    app = ClarifaiApp(api_key='{ab1b812d1beb46ff8872acea4f341b4c}')

    # Logo model

    model = app.models.get('general-v1.3')
    response = model.predict_by_url(url=post.image_url)

    if response["status"]["code"] == 10000:
        if response["outputs"]:
            if response["outputs"][0]["data"]:
                if response["outputs"][0]["data"]["concepts"]:
                    for index in range(0, len(response["outputs"][0]["data"]["concepts"])):
                        category = CategoryModel(post=post,
                                                 category_text=response["outputs"][0]["data"]["concepts"][index][
                                                     "name"])
                        category.save()
                else:
                    print "No concepts list error."
            else:
                print "No data list error."
        else:
            print "No output lists error."
    else:
        print "Response code error."



#For validating the session 
开发者ID:Manishkumar21,项目名称:Final_Project,代码行数:31,代码来源:views.py

示例5: get_clarifai_api

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def get_clarifai_api():
    return ClarifaiApp(settings.CLARIFAI_CLIENT_ID,
                       settings.CLARIFAI_CLIENT_SECRET) 
开发者ID:mariru,项目名称:fakenews,代码行数:5,代码来源:classify.py

示例6: get_clarifai_api

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def get_clarifai_api():
    return ClarifaiApp(CLIENT_ID, CLIENT_SECRET) 
开发者ID:mariru,项目名称:fakenews,代码行数:4,代码来源:clarifai_api.py

示例7: labelImage

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def labelImage(self, imageURL):
        app = ClarifaiApp()
        d = app.tag_urls([imageURL])  
        #output list, value
        count = 0

        for key, value in d.iteritems():
            if key == 'outputs':
                subDict = value
                break

        for i in subDict:
            for key, value in i.iteritems(): 
                if key == 'data':
                    subDict = value
                    break

        for key, value in subDict.iteritems(): 
            if key == 'concepts':
                subDict = value
                break

        for i in subDict:
            for key, value in i.iteritems():
                if key == 'name':
                    words.append(value)
                    if(len(words) % 4 == 0):
                        words.append('\n')
                    break
        return words 
开发者ID:Micasou,项目名称:catFaceSwapSendToTodd,代码行数:32,代码来源:clarifai.py

示例8: main

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def main():
    a = app(app_id=os.environ['CLARIFAI_CLIENT_ID'],
            app_secret=os.environ['CLARIFAI_CLIENT_SECRET'])
    models = a.models.get_all()
    for m in models:
        info = m.get_info()
        model = info['model']
        print(model['name'] + '\t' \
              + model['id'] + '\t' \
              + model['created_at']) 
开发者ID:28mm,项目名称:Fovea,代码行数:12,代码来源:clarifai-models.py

示例9: main

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def main():
    app = ClarifaiApp()
    #image_set = create_image_set('/Users/mehty/Desktop/UofThacks/face-shape-recognition/Heart/', ['heart-face'])
    #app.inputs.bulk_create_images(image_set)
    model = app.models.create(model_id="FACE-SHAPES", concepts=['heart-face'], not_concepts=['diamond-face'])
    model.train()

    #model = app.models.get('face-shapes')
    #url = raw_input("base64 encoded image bytes: ")
    #print model.predict_by_url(url = 'http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg')['outputs'][0]['data']['concepts'] 
开发者ID:Mehty,项目名称:HairStyler,代码行数:12,代码来源:Heart.py

示例10: main

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def main():
	app = ClarifaiApp()
	model = app.models.get('general-v1.3')
	
	bytes = raw_input("base64: ")
	print model.predict_by_base64(bytes)['outputs'][0]['data']['concepts'] 
开发者ID:Mehty,项目名称:HairStyler,代码行数:8,代码来源:general.old.py

示例11: create_image_set

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def create_image_set(img_path):
	app = ClarifaiApp()
	model = app.models.get('general-v1.3')
	images = {}
	for file_path in glob(os.path.join(img_path, '*.jpg')):
		print(file_path)
		images[file_path] = model.predict_by_filename(file_path)['outputs'][0]['data']['concepts']

	return images 
开发者ID:Mehty,项目名称:HairStyler,代码行数:11,代码来源:general.old.py

示例12: prediction

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def prediction(bytes):
	app = ClarifaiApp()
	model = app.models.get('general-v1.3')
	
	return model.predict_by_base64(bytes)['outputs'][0]['data']['concepts'] 
开发者ID:Mehty,项目名称:HairStyler,代码行数:7,代码来源:hairstyle.py

示例13: create_image_set

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def create_image_set(img_path):
	app = ClarifaiApp()
	model = app.models.get('general-v1.3')
	images = {}
	for file_path in glob(os.path.join(img_path, '*.jpg')):
		#print(file_path)
		images[file_path] = model.predict_by_filename(file_path)['outputs'][0]['data']['concepts']

	return images


#print hairstyles 
开发者ID:Mehty,项目名称:HairStyler,代码行数:14,代码来源:hairstyle.py

示例14: main

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def main():
	photoApp = ClarifaiApp()
	imagePaths = ['dogInStroller', 'happyCouple', 'stopSign', 'stuffedAnimal', 'baby'] 
	#go through each search concept folder
	for searchItem in imagePaths:
		path = './pictures/' + searchItem
		photoCollection = make_photo_collection(path, searchItem)
		photoApp.inputs.bulk_create_images(photoCollection)
			#***need to fix the make and train... not sure why clarifai is trying to charge?
		#make_and_train(searchItem, photoApp)

#doesn't seem to be uploading all the pictures, fix this later 
开发者ID:sara,项目名称:PhotoHunt,代码行数:14,代码来源:photoModels.py

示例15: checkPhoto

# 需要导入模块: from clarifai import rest [as 别名]
# 或者: from clarifai.rest import ClarifaiApp [as 别名]
def checkPhoto(pictureURL, tag):
	resp = twiml.Response()
	photoApp = ClarifaiApp()
	#all concepts attached to the item specified in photo database (i.e. answer key)
	with app.app_context():
		conceptGoals = mongo.db.photoGoals.find_one({"item":tag})
	model = photoApp.models.get(tag)
	image = ClImage(url='https://samples.clarifai.com/metro-north.jpg')
	#all data associated with each concept: id, name, appid, and value
	predictionData = model.predict([image])['outputs'][0]['data']['concepts']
	#['outputs']['data']['concepts']
	#predictionData = predictionData.replace("'", '"')
	#dataDict = json.loads(predictionData)
	#concepts = predictionData.get('outputs')
	print(predictionData)
	#userConcepts = []
	#for x in predictionData:
	#	userConcepts.append(x[1])
	#all concepts included in user's photo
	#conceptsPresent = conceptGoals.intersection(userConcepts)
	#numbers = []
	#for x in conceptsPresent:
		#threshold for approval is 51%
	#	probability = predictionData["value"]
	#	if probability > 0.5:
	#		numbers.append(probability)
	#if numbers.length > 2:
	#	return True
	#else:
	#	return False 
开发者ID:sara,项目名称:PhotoHunt,代码行数:32,代码来源:viewsTester.py


注:本文中的clarifai.rest.ClarifaiApp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。