コード例 #1
0
def local_post():
    uploaded_files = request.files.getlist('local_files')
    # uploaded_files = webpage_utils.filestorage_to_binary(uploaded_files)
    args = {'files': uploaded_files}

    try:
        message = api.predict_data(args)
    except Exception as error:
        print(error)
        flash(Markup(error))
        code = error.code if hasattr(error, 'code') else 500
        return render_template('index.html'), code

    return render_template('results.html', predictions=message['predictions'])
コード例 #2
0
def test_predict_data():
    print('Testing local: predict data ...')
    from deepaas.model.v2.wrapper import UploadedFile
    from imgclas.api import predict_data

    fpath = os.path.join(paths.get_base_dir(), 'data', 'samples', 'sample.jpg')
    tmp_fpath = os.path.join(paths.get_base_dir(), 'data', 'samples',
                             'tmp_file.jpg')
    copyfile(fpath, tmp_fpath
             )  # copy to tmp because we are deleting the file after prediction
    file = UploadedFile(name='data',
                        filename=tmp_fpath,
                        content_type='image/jpg')
    args = {'files': [file]}
    r = predict_data(args)
コード例 #3
0
def api_fn():

    mode = request.form.get('mode')
    if mode == 'url':
        im_list = request.form.getlist('url_list')
        message = api.predict_url(im_list, merge=True)
    elif mode == 'localfile':
        im_list = request.files.to_dict().values()
        im_list = webpage_utils.filestorage_to_binary(im_list)
        message = api.predict_data(images=im_list)
    else:
        message = {'status': 'error', 'Error_type': 'Invalid mode'}

    js = json.dumps(message)
    if message['status'] == 'ok':
        resp = Response(js, status=200, mimetype='application/json')
    if message['status'] == 'error':
        resp = Response(js, status=400, mimetype='application/json')

    return resp
コード例 #4
0
def test_predict_data():
    fpath = os.path.join(paths.get_base_dir(), 'data', 'samples', 'sample.jpg')
    file = FileStorage(open(fpath, 'rb'))
    args = {'files': file}
    results = predict_data(args)