當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。