コード例 #1
0
def url_post():
    url_list = request.form['url']
    url_list = [i.replace(' ', '') for i in url_list.split(' ') if i != '']
    args = {'urls': url_list}

    try:
        message = api.predict_url(args, merge=True)
    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 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
コード例 #3
0
def test_predict_url():
    print('Testing local: predict url ...')
    from imgclas.api import predict_url

    args = {'urls': [test_url]}
    r = predict_url(args)
コード例 #4
0
def test_predict_url():
    url = 'https://file-examples.com/wp-content/uploads/2017/10/file_example_JPG_100kB.jpg'
    args = {'urls': [url]}
    results = predict_url(args)