Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 30 10:32:40 2019
@author: naresh.gangiredd
"""
import os
import json
from sklearn.externals import joblib
import flask
import boto3
import time
import pyarrow
from pyarrow import feather
#from boto3.s3.connection import S3Connection
#from botocore.exceptions import ClientError
#import pickle
import modin.pandas as pd
import logging
#Define the path
prefix = '/opt/ml/'
model_path = os.path.join(prefix, 'model')
logging.info("Model Path" + str(model_path))
# Load the model components
regressor = joblib.load(os.path.join(model_path, 'Regx.pkl'))
logging.info("Regressor" + str(regressor))
# The flask app for serving predictions
app = flask.Flask(__name__)
@app.route('/ping', methods=['GET'])
def ping():
# Check if the classifier was loaded correctly
try:
#regressor
status = 200
logging.info("Status : 200")
except:
status = 400
return flask.Response(response= json.dumps(' '), status=status, mimetype='application/json' )
@app.route('/invocations', methods=['POST'])
def transformation():
# Get input JSON data and convert it to a DF
input_json = flask.request.get_json()
input = input_json['input']['exp1']
predictions = float(regressor.predict([[input]]))
# Transform predictions to JSON
result = {
'output': predictions
}
resultjson = json.dumps(result)
return flask.Response(response=resultjson, status=200, mimetype='application/json')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment