<commit_before>from secrets import KAIROS_APP_ID, KAIROS_APP_KEY

import requests
import json
import base64

def base64_img(fp):
    with open(fp, "rb") as image_file:
        return base64.b64encode(image_file.read())

def kairos_post(endpoint, data):
    headers = { "content-type" : "application/json",
                "app_id" : KAIROS_APP_ID,
                "app_key" : KAIROS_APP_KEY}

    r = requests.post("http://api.kairos.com/" + endpoint, data=json.dumps(data), headers=headers)
    return r

def add_face_file(base64_img, name, gallery):
    data = {"image" : base64_img,
            "subject_id" : "<NAME>",
            "gallery_name" : "test"}

    r = kairos_post("enroll", data)

    # returns true if this succeeds
    return 'Errors' not in r.json()

def add_face_url(img_url, name, gallery):
    data = {"url" : img_url,
            "subject_id" : "<NAME>",
            "gallery_name" : "test"}

    r = kairos_post("enroll", data)

    # returns true if this succeeds
    return 'Errors' not in r.json()

def check_face_file(base64_img, gallery):
    data = {"image" : base64_img,
            "threshold" : 0.7,
            "gallery_name" : "test"}

    r = kairos_post("recognize", data)

    import pdb; pdb.set_trace()

    return True

def check_face_url(img_url, gallery):
    return True

# # test enroll

# r = add_face_file(base64_img('test_pix/daniel6.jpg'), 'danielm', 'test')
r = check_face_file(base64_img('test_pix/adam3.jpg'), 'test')

import pdb; pdb.set_trace() 

# # test recognize 75%
# data = {"image" : base64_img('test_pix/daniel6.jpg'),
#         "threshold" : 0.5,
#         "gallery_name" : "test"}

# r = kairos_post("recognize", data)
# print r.json()

print base64_img('test_pix/daniel6.jpg')<commit_msg>all api calls should be implemented correctly<commit_after>from secrets import KAIROS_APP_ID, KAIROS_APP_KEY

import requests
import json
import base64

def base64_img(fp):
    with open(fp, "rb") as image_file:
        return base64.b64encode(image_file.read())

def kairos_post(endpoint, data):
    headers = { "content-type" : "application/json",
                "app_id" : KAIROS_APP_ID,
                "app_key" : KAIROS_APP_KEY}

    r = requests.post("http://api.kairos.com/" + endpoint, data=json.dumps(data), headers=headers)
    return r

def add_face_file(base64_img, name, gallery):
    data = {"image" : base64_img,
            "subject_id" : "<NAME>",
            "gallery_name" : "test"}

    r = kairos_post("enroll", data).json()

    # returns true if this succeeds
    return 'Errors' not in r

def add_face_url(img_url, name, gallery):
    data = {"url" : img_url,
            "subject_id" : "<NAME>",
            "gallery_name" : "test"}

    r = kairos_post("enroll", data).json()

    # returns true if this succeeds
    return 'Errors' not in r

def check_face_file(base64_img, gallery):
    data = {"image" : base64_img,
            "threshold" : 0.7,
            "gallery_name" : "test"}

    r = kairos_post("recognize", data).json()

    # returns true if this succeeds
    return r.get('images')[0].get('transaction').get('status') == 'success'

def check_face_url(img_url, gallery):
    data = {"url" : img_url,
            "threshold" : 0.7,
            "gallery_name" : "test"}

    r = kairos_post("recognize", data).json()

    # returns true if this succeeds
    return r.get('images')[0].get('transaction').get('status') == 'success'


# test enroll
# r = add_face_file(base64_img('test_pix/daniel6.jpg'), 'danielm', 'test')

# test recognize
# r = check_face_file(base64_img('test_pix/daniel6.jpg'), 'test')
{'fraction_non_alphanumeric': 0.14452473596442467, 'fraction_numerical': 0.017231795441912175, 'mean_word_length': 3.155889145496536, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2512872', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1256, 'n_words': 280}