Exemplo n.º 1
0
def get_person_data_callback():
    data = request.get_json()
    if not verify_data(data, "id"):
        resp = {
            "status_code": status_codes["insufficient_data"], 
            "message": response_messages["insufficient_data"]
        }
        return jsonify(resp)
    data_dir = os.path.join(PERSON_DATA_PATH, data["id"]+".json")
    if not os.path.exists(data_dir):
        resp = {
            "status_code": status_codes["person_not_found"], 
            "message": response_messages["person_not_found"]
        }
        return jsonify(resp)
    d_json = get_person_data(data["id"])
    temp = get_person_data_from_database(data["id"])
    if temp is not None:
        d_json["star"] = temp["star"]
    img_dir = os.path.join(FACE_IMAGE_PATH, d_json["image"])
    d_json["image"] = encode_to_base64(img_dir)
    resp = {
        "status_code": status_codes["success"], 
        "message": response_messages["success"], 
        "data": d_json
    }
    return jsonify(resp)
Exemplo n.º 2
0
def download_file_from_service(uniq_file_key):
    ''' downloads file data from remote service in string base64 coding '''

    try:
        data_raw = obj_saver.download(get_download_file_link(uniq_file_key))
    except WrongLinkValueError:
        return None, 'wrong link to file'
    except DoesNotExist:
        return None, 'wrong key'
    except FieldDoesNotExist:
        return None, 'needs name "key"'
    return encode_to_base64(data_raw), None
Exemplo n.º 3
0
def get_starred_persons_callback():
    persons = get_starred_persons()
    result = []
    for mid, star in persons:
        json_d = get_person_data(mid)
        json_d["star"] = star
        img_dir = os.path.join(FACE_IMAGE_PATH, json_d["image"])
        json_d["image"] = encode_to_base64(img_dir)
        result.append(json_d)

    resp = {
        "status_code": status_codes["success"], 
        "message": response_messages["success"], 
        "result": result
    }
    return jsonify(resp)
Exemplo n.º 4
0
def image_anti_porn(filename, token, proxy_dict=None):
    '''
    process the image tagging
    :param image_base64_str:
    :return:
    '''
    image_base64_str = utils.encode_to_base64(filename)

    _payload = {"image": image_base64_str}
    _url = "%s/v1.0/moderation/image/anti-p**n" % ais.ENDPOINT
    _headers = {'Content-Type': 'application/json',
                'X-Auth-Token': token}

    if proxy_dict is None:
        r = requests.post(_url, json=_payload, headers=_headers)
    else:
        r = requests.post(_url, json=_payload, headers=_headers, proxies=proxy_dict)
    return r.json()
Exemplo n.º 5
0
def image_anti_porn(filename, token, proxy_dict=None):
    '''
    process the image tagging
    :param image_base64_str:
    :return:
    '''
    image_base64_str = utils.encode_to_base64(filename)

    _payload = {"image": image_base64_str}
    _url = "%s/v1.0/moderation/image/anti-p**n" % ais.ENDPOINT
    _headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}

    if proxy_dict is None:
        r = requests.post(_url, json=_payload, headers=_headers)
    else:
        r = requests.post(_url,
                          json=_payload,
                          headers=_headers,
                          proxies=proxy_dict)
    return r.json()
Exemplo n.º 6
0
def recature_detect(filename, token, proxy_dict=None):
    '''
    process the recature detect
    :param image_base64_str:
    :return:
    '''
    image_base64_str = utils.encode_to_base64(filename)

    _payload = {"image": image_base64_str,
               "threshold": 0.99,
               "scene": ["recapture"]
               }
    _url = "%s/v1.0/image/recapture-detect" % ais.ENDPOINT
    _headers = {'Content-Type': 'application/json',
                'X-Auth-Token': token}

    if proxy_dict is None:
        r = requests.post(_url, json=_payload, headers=_headers)
    else:
        r = requests.post(_url, json=_payload, headers=_headers, proxies=proxy_dict)
    return r.json()
Exemplo n.º 7
0
def tagging(filename, token, proxy_dict=None):
    '''
    process the image tagging
    :param image_base64_str:
    :return:
    '''
    image_base64_str = utils.encode_to_base64(filename)

    _payload = {"image": image_base64_str,
               "url": "",
               "threshold": "30",
               "language": "zh"
               }
    _url = "%s/v1.0/image/tagging" % ais.ENDPOINT
    _headers = {'Content-Type': 'application/json',
                'X-Auth-Token': token}

    if proxy_dict is None:
        r = requests.post(_url, json=_payload, headers=_headers)
    else:
        r = requests.post(_url, json=_payload, headers=_headers, proxies=proxy_dict)
    return r.json()
Exemplo n.º 8
0
def get_face_image_callback():
    data = request.get_json()
    if not verify_data(data, "image_name"):
        resp = {
            "status_code": status_codes["insufficient_data"], 
            "message": response_messages["insufficient_data"]
        }
        return jsonify(resp)
    img_name = data["image_name"]
    img_dir = os.path.join(FACE_IMAGE_PATH, img_name)
    if not os.path.exists(img_dir):
        resp = {
            "status_code": status_codes["image_not_found"], 
            "message": response_messages["image_not_found"]
        }
        return jsonify(resp)
    resp = {
        "status_code": status_codes["success"], 
        "message": response_messages["success"]
    }
    resp["image_data"] = encode_to_base64(img_dir)
    return jsonify(resp)
Exemplo n.º 9
0
def search_person_callback():
    data = request.get_json()
    if not verify_data(data, "name"):
        resp = {
            "status_code": status_codes["insufficient_data"], 
            "message": response_messages["insufficient_data"]
        }
        return jsonify(resp)
    persons = search_person_by_name(data["name"], limit=100)
    result = []
    for mid, star in persons:
        json_d = get_person_data(mid)
        json_d["star"] = star
        img_dir = os.path.join(FACE_IMAGE_PATH, json_d["image"])
        json_d["image"] = encode_to_base64(img_dir)
        result.append(json_d)

    resp = {
        "status_code": status_codes["success"], 
        "message": response_messages["success"], 
        "result": result
    }
    return jsonify(resp)
Exemplo n.º 10
0
def recature_detect(filename, token, proxy_dict=None):
    '''
    process the recature detect
    :param image_base64_str:
    :return:
    '''
    image_base64_str = utils.encode_to_base64(filename)

    _payload = {
        "image": image_base64_str,
        "threshold": 0.99,
        "scene": ["recapture"]
    }
    _url = "%s/v1.0/image/recapture-detect" % ais.ENDPOINT
    _headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}

    if proxy_dict is None:
        r = requests.post(_url, json=_payload, headers=_headers)
    else:
        r = requests.post(_url,
                          json=_payload,
                          headers=_headers,
                          proxies=proxy_dict)
    return r.json()
Exemplo n.º 11
0
    #
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests, 
    # there is no this problem. 
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()
    return resp


if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use
    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/bank.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = ocr_bank_card(token, '', demo_data_url)
    print result

    # call interface use the data
    result = ocr_bank_card(token, encode_to_base64('data/bank.jpg'), '', True)
    print result
Exemplo n.º 12
0
    #
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests,
    # there is no this problem.
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()
    return resp


if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use
    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/tagging-normal.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = image_antiporn(token, '', demo_data_url)
    print result

    # call interface use the file
    result = image_antiporn(token, encode_to_base64('data/tagging-normal.jpg'))
    print result
Exemplo n.º 13
0
    # 500 error in the single urlopen function.
    #
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests, 
    # there is no this problem. 
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()        
    return resp 

if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use
    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/tagging-normal.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = image_antiporn(token, '', demo_data_url )
    print result

    # call interface use the file
    result = image_antiporn(token, encode_to_base64('data/tagging-normal.jpg'))
    print result
Exemplo n.º 14
0
    #
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests,
    # there is no this problem.
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()
    return resp


if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use
    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/qr-code.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = ocr_qr_code(token, '', demo_data_url)
    print result

    # call interface use the file
    result = ocr_qr_code(token, encode_to_base64('data/qr-code.jpg'))
    print result
Exemplo n.º 15
0
    #
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests,
    # there is no this problem.
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()
    return resp


if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use
    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/bank.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = ocr_bank_card(token, '', demo_data_url)
    print result

    # call interface use the data
    result = ocr_bank_card(token, encode_to_base64('data/bank.jpg'), '', True)
    print result
Exemplo n.º 16
0
    #
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests, 
    # there is no this problem. 
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()        
    return resp

if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use

    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/asr-sentence.wav'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = asr_sentence(token, '', demo_data_url, 'wav', '16k')
    print result

    # call interface use the file
    result = asr_sentence(token, encode_to_base64('data/asr-sentence.wav'), '', 'wav', '16k')
    print result
Exemplo n.º 17
0
    #
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests,
    # there is no this problem.
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()
    return resp


if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'
    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/barcode.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = ocr_barcode(token, '', demo_data_url)
    print result

    # call interface use the data
    result = ocr_barcode(token, encode_to_base64('data/barcode.jpg'))
    print result
Exemplo n.º 18
0
    #
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests, 
    # there is no this problem. 
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()
    return resp


if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'
    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/barcode.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = ocr_barcode(token, '', demo_data_url)
    print result

    # call interface use the data
    result = ocr_barcode(token,  encode_to_base64('data/barcode.jpg'))
    print result
Exemplo n.º 19
0
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests, 
    # there is no this problem. 
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()
    return resp


if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use
    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/qr-code.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = ocr_qr_code(token, '', demo_data_url)
    print result

    # call interface use the file
    result = ocr_qr_code(token, encode_to_base64('data/qr-code.jpg'))
    print result