コード例 #1
0
def api_root():
    """
    Reads the image from request.
    Runs the model.
    Returns the JSON output.
    Args: HTTP post request with an image file specified to the key 'image'
    """
    app.logger.info('Project_Home:' + PROJECT_HOME)
    if request.method == 'POST':
        #print(request.form['image'])
        ## Read the image file.
        #img = request.form['image']
        #print(request.form['image'].encode('utf-8'))
        #img = base64.b64decode(request.form['image'].encode('utf-8')).decode('utf-8')
        #img = request.form['image'].decode('base64')
        #imgData = request.form['image'][:-1]
        #imgData = imgData[22:] 
        #print(imgData)
        #img = base64.b64decode(imgData)
        encoded = request.form['image'].split(",", 1)[1] 
        print(encoded)
        #img_data = b64decode(encoded)
        img_data = a2b_base64(encoded)
        with open("test_images/test_32.png", "wb") as f:
          f.write(img_data)
        rgba_image = Image.open("test_images/test_32.png")
        rgb_image = rgba_image.convert('RGB')
        rgb_image.save("test_images/test.png")
        response = classifier_new.main(classifier_new.parse_arguments([])) 
        print(response)
        ## Return the JSON response to the API request.
        return jsonify({'data': response}) 
        #return response
    else:
    	return "Where is the image?"
コード例 #2
0
def api_root():
    """
    Reads the image from request.
    Runs the model.
    Returns the JSON output.
    Args: HTTP post request with an image file specified to the key 'image'
    """
    app.logger.info('Project_Home:' + PROJECT_HOME)
    if request.method == 'POST':
        print(request.data)
        #encoded = request.form['image'].split(",", 1)[1]
        #print(encoded)
        encoded = request.data.decode("utf-8").split(",", 1)[1]
        print(encoded)
        img_data = a2b_base64(encoded)
        with open("test_images/test_32.png", "wb") as f:
            f.write(img_data)
        rgba_image = Image.open("test_images/test_32.png")
        rgb_image = rgba_image.convert('RGB')
        rgb_image.save("test_images/test.png")
        resp = classifier_new.main(classifier_new.parse_arguments([]))
        print(resp)
        return jsonify(resp)
    else:
        return "Where is the image?"