def predict():
    """
    The second step is optional and it isn't necessary, you can comment
    that lines of code, but if you want to have a robust control of 
    the data that people post in your API you have to include in a correct
    format in the same way that the example in validation.py
    """
    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.debug(f'Inputs: {json_data}')

        # Step 2: Validate the input using marshmallow schema
        input_data, errors = validate_inputs(input_data=json_data)

        # Step 3: Model prediction
        result = make_prediction(input_data=input_data)
        _logger.debug(f'Outputs: {result}')

        # Step 4: Convert numpy ndarray to list
        predictions = result.get('predictions').tolist()
        version = result.get('version')

        # Step 5: Return the response as JSON
        return jsonify({
            'predictions': predictions,
            'version': version,
            'errors': errors
        })
Exemplo n.º 2
0
def predict():
    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.debug(f'Inputs: {json_data}')

        #Step 2: Validate the input using marshmallow schema
        input_data, errors = validate_inputs(input_data=json_data)

        # Step 3: Model prediction
        result = make_prediction(input_data=json_data)
        _logger.debug(f'Outputs: {result}')

        # Step 4: Convert numpy ndarray to list
        # This step is not happening because we
        # already did that while converting probability into
        # real values
        prediction = result.get('predictions')
        version = result.get('version')

        # Step 5: Return the response as JSON
        return jsonify({
            'predictions': prediction,
            'errors': errors,
            'version': version
        })
def predictForUser():
    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        json_data = {
            'Airline': str(request.form['Airline']),
            'Date_of_Journey': str(request.form['Date_of_Journey']),
            'Source': str(request.form['Source']),
            'Destination': str(request.form['Destination']),
            'Dep_Time': str(request.form['Dep_Time']),
            'Arrival_Time': str(request.form['Arrival_Time']),
            'Duration': str(request.form['Duration']),
            'Total_Stops': str(request.form['Total_Stops']),
            'Additional_Info': str(request.form['Additional_Info']),
        }
        
        _logger.debug(f'Inputs: {json_data}')
        
        # Step 2: Validate the input using marshmallow schema
        input_data, errors = validate_inputs(input_data=json_data, many=False)
        

        # Step 3: Model prediction
        result = make_prediction(input_data=input_data, form_input=True)
        _logger.debug(f'Outputs: {result}')

        # Step 4: Convert numpy ndarray to list
        predictions = result.get('predictions').tolist()
        version = result.get('version')

        # Step 5: Return the response as JSON
        return jsonify({'predictions': predictions,
                        'version': version,
                        'errors': errors})   
Exemplo n.º 4
0
def predict():
    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.debug(f'Inputs: {json_data}')
        #with open('outY.txt', 'w') as f:
        #    print('Filename:',
        #        request, request.get_json(),
        #        '\n\nRESULT', request.__dict__,
        #        '\n\nHeaders',request.headers,
        #        file=f)  # Python 3.x
        # Step 2: Validate the input using marshmallow schema
        input_data, errors = validate_inputs(input_data=json_data)
        # Step 3: Model prediction
        result = make_prediction(input_data=input_data)
        _logger.debug(f'Outputs: {result}')

        # Step 4: Convert numpy ndarray to list
        predictions = result.get('predictions').tolist()
        version = result.get('version')

        # Step 5: Return the response as JSON
        return jsonify({
            'predictions': predictions,
            'version': version,
            'errors': errors
        })
    else:
        return render_template('index.html')
Exemplo n.º 5
0
def predict():
    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.debug(f'Inputs: {json_data}')

        # Step 2: Validate the input using marshmallow schema
        input_data, errors = validate_inputs(input_data=json_data)

        # Step 3: Model prediction
        result = make_prediction(input_data=input_data)
        _logger.debug(f'Outputs: {result}')

        # Step 4: Convert numpy ndarray to list
        predictions = result.get('predictions').tolist()
        propensity = result.get('propensity').tolist()

        version = result.get('version')

        # Step 5: Return the response as JSON
        return jsonify({
            'predictions': predictions,
            'propensity': propensity,
            'version': version,
            'errors': errors
        })
Exemplo n.º 6
0
def predict():
    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.info(f'Inputs: {json_data}')

        print(f"JSON DATA TYPE {type(json_data)}")
        # Step 2: Validate the input using marshmallow schema
        input_data, errors = validate_inputs(input_data=json_data)

        # Step 3: Model Prediction
        print(f"INPUT DATA TYPE {type(input_data)}")
        result = make_prediction(input_data=json_data)
        _logger.info(f'Outputs: {result}')

        # Cast to int because np.array are not recognize by json
        # predictions = int(result.get('predictions')[0])
        # Step 4: Convert numpy ndarray to list
        predictions = result.get("predictions").tolist()
        version = result.get('version')

        # Step 5: Return the response as JSON
        return jsonify({
            'predictions': predictions,
            'version': version,
            'errors': errors
        })
def predict():
    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        json_data = request.get_json()

        if (type(json_data) != str):
            json_data = pd.DataFrame(json_data)
            input_data = json_data.to_json(orient='records')
        else:
            input_data = json_data

        _logger.info(f'Inputs in POST controller: {input_data}')
        _logger.info(f'Type of input: {type(input_data)}')

        # Step 2: Validate the input using marshmallow schema
        validated_data, errors = validate_inputs(input_data=input_data)
        _logger.info(f'Inputs: {input_data}')
        _logger.info(f'Inputs: {errors}')

        # Step 3: Model prediction
        result = make_prediction(input_data=validated_data)

        # Step 4: Get the prediction and model version
        predictions = (result.get('predictions')['Label']).values[0]
        version = result.get('version')

        _logger.info(f'predictions: {predictions}')

        # Step 5: Return the response as JSON

        return jsonify({
            'predictions': predictions,
            'version': version,
            'errors': errors
        })
Exemplo n.º 8
0
def prediction():
     if request.method == 'POST':
        data = request.form.to_dict(flat=False)
        _logger.debug(f'Inputs: {data}')
        input_data, errors =  validate_inputs(input_data=data)
        result = make_prediction(input_data=input_data)
        _logger.debug(f'Outputs: {result}')
        predictions = result.get('predictions').tolist()
        return render_template('prediction.html',
                               pred='Вероятность ишемической болезни сердца ≈ {}%'\
                               .format(round(predictions[0][1]*100, 1)))
def inputformpredict():
    input_features = [x for x in request.form.values()]
    final = np.array(input_features)
    data_unseen = pd.DataFrame([final], columns=cols)

    input_data = data_unseen.to_json(orient='records')
    _logger.info(f'Inputs: {input_data}')
    validated_data, errors = validate_inputs(input_data=input_data)
    result = make_prediction(input_data=validated_data)
    prediction = (result.get('predictions')['Label']).values[0]

    #prediction = predict_model(model, data=data_unseen, round = 0)
    #prediction = int(prediction.Label[0])
    return render_template('home.html',
                           pred='Expected Bill will be {}'.format(prediction))
Exemplo n.º 10
0
def predict():
    if request.method == 'POST':
        json_data = request.get_json()
        _logger.DEBUG(f'inputs:{json_data}')

        input_data, errors = validate_inputs(json_data)
        result = make_prediction(input_data=input_data)
        _logger.DEBUG(f'output:{result}')

        predictions = result.get('prediction').tolist()
        version = result.get('version')

        return (jsonify({
            'predictions': predictions,
            'version': version,
            'errors': errors
        }))
Exemplo n.º 11
0
def predict():
    if request.method == 'POST':
        #Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.debug(f'Inputs: {json_data}')
        #Validate input using marshmallow schema
        input_data, errors =  validate_inputs(input_data=json_data)

        #Model prediction
        result = make_prediction(input_data=input_data)
        _logger.debug(f'Outputs: {result}')

        predictions = result.get('predictions').tolist()
        version = result.get('version')

        return jsonify({'predictions': predictions,
                        'version': version,
                        'errors': errors})
Exemplo n.º 12
0
def predict():
    if request.method == "POST":
        json_data = request.get_json()
        _logger.info(f'Inputs: {json_data}')

        input_data, errors = validate_inputs(input_json=json_data)

        result = make_prediction(input_data=input_data)
        _logger.info(f'Outputs: {result}')

        predictions = result.get('predictions')[0]
        version = result.get('version')

        return jsonify({
            'Predictions': predictions,
            'version': version,
            'errors': errors
        })
Exemplo n.º 13
0
def predict():
    if request.method == 'POST':
        json_data = request.get_json()
        _logger.info(f'Inputs: {json_data}')

        input_data, errors = validate_inputs(input_data=json_data)
        _logger.info(f'\n!!!\nValidated inputs: {input_data}')

        result = make_prediction(input_data=input_data)
        _logger.info(f'Outputs: {result}')

        predictions = result.get('predictions').tolist()
        version = result.get('version')

        return jsonify({
            'predictions': predictions,
            'errors': errors,
            'version': version
        })
def predict():
    if request.method == 'POST':
        not_validated_json_data = request.get_json()
        #_logger.info(f'inputs: {not_validated_json_data}')

        json_data, errors = validate_inputs(input_data=not_validated_json_data)

        result = model_predict(input_data=json_data)
        _logger.info(f'outputs: {result}')

        prediction = result.get('predictions').tolist()
        version = result.get('version')

        _logger.info(f'predictions: {prediction}')

        return jsonify({
            'predictions': prediction,
            'version': version,
            'errors': errors
        })
Exemplo n.º 15
0
def predict():
    if request.method == 'POST':
        # Extract POST data from request body
        input_data = request.files

        # Validate the input data
        validated_data, errors = validate_inputs(request.files)
        _logger.debug(
            f'Number of validated files: {len(validated_data.keys())}')
        _logger.debug(f'Number of erroneous files: {len(errors.keys())}')

        # Model prediction
        audio_files = list(validated_data.values())
        result = make_prediction(input_data=audio_files)
        _logger.debug(f'Outputs: {result}')

        return jsonify({
            'predictions': list(result['predictions']),
            'version': result['version'],
            'errors': errors
        })
Exemplo n.º 16
0
def predict():
    if request.method == 'POST':
        # extract 'post' data from request body
        json_data = request.get_json()
        _logger.info(f'Inputs: {json_data}')

        # validate input (using marshmallow schema)
        input_data, errors = validate_inputs(input_data=json_data)

        # model prediction
        result = make_prediction(input_data=input_data)
        _logger.info(f'Outputs: {result}')

        # convert array to a list
        predictions = result.get('predictions').tolist()
        version = result.get('version')

        # get the response as JSON
        return jsonify({'predictions': predictions,
                        'version': version,
                        'errors': errors})
Exemplo n.º 17
0
def predict():
    if request.method == "POST":
        # Step 1: Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.debug(f"Inputs: {json_data}")

        # Step 2: Validate the input using marshmallow schema
        input_data, errors = validate_inputs(input_data=json_data)

        # Step 3: Model prediction
        result = make_prediction(input_data=input_data)
        _logger.debug(f"Outputs: {result}")

        # Step 4: Convert numpy ndarray to list
        predictions = result.get("predictions").tolist()
        version = result.get("version")

        # Step 5: Return the response as JSON
        return jsonify(
            {"predictions": predictions, "version": version, "errors": errors}
        )
Exemplo n.º 18
0
def predict():
    if request.method == 'POST':
        # Step1: Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.info(f'Inputs: {json_data}')

        # Step 2: validate the input using marshmallow schema
        input_data = json.loads (json_data)
        input_data,errors = validate_inputs(input_data=input_data)

        # _data = pd.read_json(json_data)
        result = make_prediction(input_data=input_data)
        _logger.info(f'Outputs: {result}')

        predictions = result.get('prediction')[0].tolist()
        version = result.get('version')

        return jsonify({'predictions': predictions,
                        'version': version,
                        'errors': errors
                        })
Exemplo n.º 19
0
def predict():
    if request.method == 'POST':
        # Step 1: リクエスト本文からJSONとしてPOSTデータを抽出
        json_data = request.get_json()
        _logger.debug(f'Inputs: {json_data}')

        # Step 2: marshmallowスキーマを使用して入力を検証
        input_data, errors = validate_inputs(input_data=json_data)

        # Step 3: モデル予測
        result = make_prediction(input_data=input_data)
        _logger.debug(f'Outputs: {result}')

        # Step 4: numpy ndarrayをリストに変換
        predictions = result.get('predictions').tolist()
        version = result.get('version')

        # Step 5: 応答をJSONとして返す
        return jsonify({
            'predictions': predictions,
            'version': version,
            'errors': errors
        })
Exemplo n.º 20
0
def question_similarity():
    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        json_data = request.get_json()
        #_logger.debug(f'Inputs: {json_data}')

        # Step 2: Validate the input using marshmallow schema
        sent1, sent2, errors = validate_inputs(input_data=json_data)

        # Step 3: Model prediction
        result = ft.question_similarity(sent1, sent2)
        #_logger.debug(f'Outputs: {result}')

        # Step 4: Convert numpy ndarray to list
        predictions = result  #.get('predictions').tolist()
        version = '0'  #result.get('version')

        # Step 5: Return the response as JSON
        return jsonify({
            'predictions': predictions,
            'version': version,
            'errors': errors
        })
Exemplo n.º 21
0
def output_specific_model(model_id):
    model_id = model_id
    # lightgbm_output_v0.1-1588759220.335498

    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        data = request.get_json()

        # Step 2: Validate the input using marshmallow schema
        data, errors = validate_inputs(input_data=data)

        # Step 3: Model prediction
        result = make_prediction(input_data=data, id_model=model_id)

        predictions = result.get('predictions').tolist()
        version = result.get('version')

    return jsonify({
        'result': predictions,
        'model': model_id,
        'version': version,
        'errors': errors
    })
def version():
    if request.method == 'GET':
        return jsonify({'model_version': _version,
                        'api_version': api_version})


@prediction_app.route('/v1/predict/regression', methods=['POST'])
def predict():
    if request.method == 'POST':
        # Step 1: Extract POST data from request body as JSON
        json_data = request.get_json()
        _logger.debug(f'Inputs: {json_data}')

        # Step 2: Validate the input using marshmallow schema
<<<<<<< HEAD
        input_data, errors = validate_inputs(input_data=json_data)
=======
        input_data, errors = validate_inputs(input_json=json_data)
>>>>>>> 6162c318b58b225e0061fccd6c64cd67fe205c1b

        # Step 3: Model prediction
        result = make_prediction(input_data=input_data)
        _logger.debug(f'Outputs: {result}')

        # Step 4: Convert numpy ndarray to list
        predictions = result.get('predictions').tolist()
        version = result.get('version')

        # Step 5: Return the response as JSON
        return jsonify({'predictions': predictions,
                        'version': version,