Exemple #1
0
def create_pic(test_num, names, model_name):
    if not names[model_name]:
        name = '1'
    else:
        name = str(max(names[model_name]) + 1)

    folder_name = 'result_' + model_name[-1]
    if model_name[-1] == '1':
        score = model.predict(test_num, 1, folder_name, name)
    elif model_name[-1] == '2':
        score = model.predict(test_num, 2, folder_name, name)
    elif model_name[-1] == '3':
        score = model.predict(test_num, 3, folder_name, name)
    return name, score
async def create_prediction(filename: str = ""):
    """
    Creates a new prediction using the model. This method must be called after the init() method has run
    at least once, otherwise this will fail with a HTTP Error. When given a filename, the server will create a
    file-like object of the image file and pass that to the predict() method.

    :param filename: Image file name for an image stored in shared Docker volume photoanalysisserver_images
    :return: JSON with field "result" containing the results of the model prediction.
    """

    # Ensure model is ready to receive prediction requests
    if not model_settings.ready_to_predict:
        raise PredictionException()

    # Attempt to open image file
    try:
        image_file = open('src/images/' + filename, 'r')
        image_file.close()
    except IOError:
        logger.debug('Unable to open file: ' + filename)
        return JSONResponse(status_code=status.HTTP_400_BAD_REQUEST,
                            content={
                                "status":
                                'failure',
                                "detail":
                                "Invalid file name provided: [" + filename +
                                "]. Unable to find image on server."
                            })

    # Create prediction with model
    result = predict(image_file)

    return {'status': 'success', "result": result}
Exemple #3
0
def info():
    """
    returns the text required from the subject and topic given.

    :return: the information required.
    """
    # extracting information on the query
    user_email = request.args.get('email')
    topic = request.args.get('topic')
    subject = request.args.get('subject')

    print(f'email: {user_email}, topic: {topic}, subject: {subject}')

    # gathering information of the student from the database
    student_info = database.get_student_info(user_email)
    # print(f'student details: {student_info}')

    # predicting the marks of the student.
    marks = model.predict(student_info, subject)
    print(f'the marks of the student is: {marks}')

    # getting the information.
    info = database.get_info_file(subject, topic)

    # getting the text depending on the student marks.
    if marks < 20:
        info = info["Weak"]
    elif 20 <= marks <= 70:
        info = info["Average"]
    else:
        info = info["Intelligent"]

    return jsonify({'status': 200, 'info': info})
Exemple #4
0
def main(request):
    """Responds to any HTTP request.
    Args:
        request (flask.Request): HTTP request object.
    Returns:
        The response text or any set of values that can be turned into a
        Response object using
        `make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
    """
    request_json = request.get_json()
    # @TODO add any request validations that you need
    result = predict(model=model, input=request_json)
    return jsonify(result)
Exemple #5
0
def predict_image(image_hash, image_file_name, server_port, model_name):

    result = predict(image_file_name)  # Create prediction on model

    try:  # Send prediction results back to server
        headers = {'api_key': API_KEY}
        r = requests.post('http://host.docker.internal:' + server_port +
                          '/model/predict_result',
                          headers=headers,
                          json={
                              'model_name': model_name,
                              'image_hash': image_hash,
                              'results': result
                          })
        r.raise_for_status()
    except (requests.exceptions.ConnectionError, requests.exceptions.Timeout,
            requests.exceptions.HTTPError):
        print('Unable to send prediction results to server. Hash: "' +
              image_hash + '"')
Exemple #6
0
async def create_prediction(image_file: UploadFile = File(...)):
    """
    Creates a new prediction using the model. This method must be called after the init() method has run
    at least once, otherwise this will fail with a HTTP Error. When given a filename, the server will create a
    file-like object of the image file and pass that to the predict() method.

    :param filename: Image file name for an image stored in shared Docker volume photoanalysisserver_images
    :return: JSON with field "result" containing the results of the model prediction.
    """

    # Ensure model is ready to receive prediction requests
    if not model_settings.ready_to_predict:
        raise PredictionException()

    # Create prediction with model
    result = predict(image_file)

    return {
        'status': 'success',
        "result": result
    }
Exemple #7
0
from src.model.model import predict, load_model

model = load_model()


def {{.FunctionName}}(event, context):
    """Responds to any HTTP request.
    Args:
        event (usually a dict): An event is a JSON-formatted document that contains 
        data for a Lambda function to process.
        context: This object provides methods and properties that provide information 
        about the invocation, function, and runtime environment. 
    Returns:
        If the handler returns objects that can't be serialized by json.dumps, 
        the runtime returns an error. 
    """
    # @TODO add any request validations that you need
    return predict(model=model, input=event)
Exemple #8
0
def main():
    request_json = request.get_json()
    # @TODO add any request validations that you need
    result = predict(model=model, input=request_json)
    return jsonify(result)
Exemple #9
0
from flask import jsonify

from src.model.model import predict, load_model

model = load_model()


def {{.FunctionName}}(request):
    """Responds to any HTTP request.
    Args:
        request (flask.Request): HTTP request object.
    Returns:
        The response text or any set of values that can be turned into a
        Response object using
        `make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
    """
    request_json = request.get_json()
    # @TODO add any request validations that you need
    result = predict(model=model, input=request_json)
    return jsonify(result)
def test_predict(input_dict, expected, test_model):
    result = model.predict(test_model, input_dict)
    assert result == expected