コード例 #1
0
def fune():
    pic = request.form['picture']
    model = c_app.models.get('food-items-v1.0')
    image = CImage(pic)
    result = model.predict([image])
    print(result['outputs'][0]['data']['concepts'])
    healthy = 1

    # Transfer money if food is healthy
    if healthy:

        url = 'http://api.reimaginebanking.com/accounts/{}/transfers?key={}'.format(
            parent, apiKey)
        payload = {
            "medium": "balance",
            "payee_id": child,
            "amount": 0.01,
            "transaction_date": "2017-04-09",
            "description": "Money transferred for healthy food"
        }

        response = requests.post(
            url,
            data=json.dumps(payload),
            headers={'content-type': 'application/json'},
        )

        if response.status_code == 201:
            print('money transferred')

    return "yay"
コード例 #2
0
def process_image():
    # i = '11111111111111111111111111' + '11111100111111111100111111' + '11110001111100111110001111' + '11000001111000011110000011' +'10000000111000011100000001' +'10000000000000000000000001' +'00000000000000000000000000' +'00000000000000000000000000' +'10000000000000000000000001' +'10000110001000010001100001' +'11001111111100111111110011' +'11100111111100111111100111' + '11111111111111111111111111'

    # im = Image.open(io.BytesIO(i))
    # im.show()
    image = request.get_data()

    with open('image.png', 'wb') as f:
        f.write(base64.b64decode(image))

    # image = CImage(url='http://media.npr.org/assets/img/2012/02/04/dietcoke_custom-0473c1516f8a6fd514e84622d0e092ae0172a66c-s300-c85.jpg')
    image = CImage(file_obj=open('./image.png', 'rb'))
    res = model.predict([image])

    # print(res)

    prediction = res['outputs'][0]['data']['concepts'][0]['name']

    item_code = ncr.getItem(prediction)['itemCode']

    price = ncr.getItemPrice(item_code)

    # print(prediction)
    # print(price)

    return json.dumps({"price": price})
コード例 #3
0
def image_request():
	name = request.headers.get('name')
	image = request.get_json(force=True).split(';')[-1].split(',')[-1]
	name_split = name.split('.')
	file_name = name_split[0]
	extension = name_split[1]
	url = 'https://www.googleapis.com/upload/storage/v1/b/recipeanut-images/o?uploadType=media&name={}'.format(file_name)
	body = image.decode('base64')
	headers={
		"Content-Type": "image/{}".format(extension)
	}
	http = httplib2.Http()
	resp_headers, resp_body = http.request(url, method='POST', headers=headers, body=body)
	
	serving_url = 'https://storage.googleapis.com/recipeanut-images/{}'.format(file_name)
	
	model = clar_app.models.get('food-items-v1.0')
	image = CImage(url=serving_url)
	resp = model.predict([image])
	if resp['status']['description'] == 'Ok':
		items = {}
		index = 0
		for item in resp['outputs'][0]['data']['concepts']:
			food = extract_image_data(item)
			if food != '':
				items[index] = food
				index += 1
		return json.dumps(items)
	return 'Image could not be read.'
コード例 #4
0
def pic_colors(**kwargs):
    logger.critical("Extracting key colors")
    model = app.models.get('color')
    image = CImage(**kwargs)
    output = model.predict([image])
    colors = output['outputs'][0]['data']['colors']
    for c in colors:
        c['hsv'] = hsv_color(c['raw_hex'])
    return sorted(colors, key=lambda c: -c['value'])
コード例 #5
0
def getData(model, venues):
    venueColorDict = {}
    for x in range(len(venues)):
        image = CImage(url=venues[x][1])
        imageData = model.predict([image])
        colors = imageData['outputs'][0]['data'][
            'colors']  #current color palette
        colorPalette = []
        for y in range(len(colors)):
            colorPalette.append(colors[y]['raw_hex'])
        venueColorDict[venues[x][0]] = colorPalette
    return venueColorDict
コード例 #6
0
def post(imagePath):

    f = open("./Keys/key_clarifai.txt","r")
    key = f.readline()
    f.close()

    # - `CLARIFAI_API_KEY`
    app = ClarifaiApp(api_key=key)


    model = app.models.get('food-items-v1.0')
    image = CImage(file_obj=open(imagePath, 'rb'))

    #output this to JSON
    with open ('./output_data/results.json', 'w') as f:
        json.dump(model.predict([image]),f)
コード例 #7
0
ファイル: app.py プロジェクト: krnch/graffitimatch
def uploaded_file(filename):

    model = app1.models.get('graffiti')
    image = CImage(
        file_obj=open('/home/karan/flaskapp/uploads/' + str(filename), 'rb'))
    z = model.predict([image])
    values = []
    print(z, file=sys.stderr)
    results = z['outputs'][0]['data']['concepts']
    for tag in results:
        print(tag['name'], file=sys.stderr)
        print(tag['value'], file=sys.stderr)
        values.append(tag['name'])
        values.append(tag['name'])
    #print (len(results), file=sys.stderr)
    #print i['name']

    print(str(z['outputs'][0]['data']['concepts'][0]), file=sys.stderr)

    return app.send_static_file('finalview.html')
コード例 #8
0
ファイル: views.py プロジェクト: yuvrajsingh123/InstaClone
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            #checking if form is valid or not
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                #saving posts
                post.save()

                apikey = 'lBzto9IhYQnI8Z6kd4dFap0gGbFexBgRBknxuISGFK4'
                request_url = (
                    'https://apis.paralleldots.com/sentiment?sentence1=%s&apikey=%s'
                ) % (caption, apikey)
                print 'POST request url : %s' % (request_url)
                sentiment = requests.get(request_url, verify=False).json()
                sentiment_value = sentiment['sentiment']

                path = str(BASE_DIR + '\\' + post.image.url)

                #imgur api key
                client = ImgurClient(
                    "315c0833408f9c0",
                    "ab94bfdc68d430ac6f7aa5f16260b1f5d6e27b5e")
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                print post.image_url
                post.save()

                #keywords that will be helpful in accessing dirty area post
                keywords = [
                    'garbage', 'waste', 'trash', 'dirt', 'pollution', 'dust'
                ]
                value_list = []
                app = ClarifaiApp(api_key='ecc5aea7265040b4b320b3446f96152c')

                model = app.models.get('general-v1.3')
                image = CImage(url=post.image_url)
                prediction = model.predict([image])

                for i in range(
                        0, len(prediction['outputs'][0]['data']['concepts'])):
                    if prediction['outputs'][0]['data']['concepts'][i][
                            'name'] in keywords:
                        value = prediction['outputs'][0]['data']['concepts'][
                            i]['value']
                        value_list.append(value)
                    #
                    # checking condition
                if (sentiment_value < 0.6 and max(value_list) > 0.8):
                    print 'dirty image'
                    send_mail(post.image_url)

                return redirect('/feed/')

        else:
            form = PostForm()

            #return post html page
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #9
0
from clarifai import rest
from clarifai.rest import ClarifaiApp
app1 = ClarifaiApp("fXY39wieIcnVwRxNlu4d2HbKGupLzHXrvF1rYPMZ",
                   "y6-0qljij7SOOVC1FuRylVhKh7lgeLDu-TIbfkCW")
from clarifai.rest import Image as CImage
import csv

filename = './final_graffiti.csv'

print("# for row in csv_reader:")
count = 0
with open(filename, 'r') as count_file:

    csv_reader = csv.reader(count_file)
    for row in csv_reader:
        count += 1
        if count == 100:
            break
        print count
        model = app1.models.get('nsfw-v1.0')
        image = CImage(url=str(row[0]))
        print(model.predict([image]))
コード例 #10
0
def get_ingredients(image):
    model = app.models.get('food-items-v1.0')
    image = CImage(url=image)
    return model.predict([image])