I have deployed an ML model trained with combining CSVs through dataset. When I try to consume the model REST endpoint through python. I get 502 error. In score.py, I predicted by using the dataset in the workspace as I need to use Count vectorizer. Below is my score.py code for your reference.
def init():
global model
model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), "prediction-model.pickle")
model = joblib.load(model_path)
def run(data):
try:
data = json.loads(data)['data']
print(data)
workspace = Workspace.get(name="xxx", subscription_id='xxx',
resource_group='xxx')
dataset_name = 'prediction_ds'
prediction_ds = Dataset.get_by_name(workspace=workspace, name=dataset_name)
df = prediction_ds.to_pandas_dataframe()
df = df[pd.notnull(df['DESCRIPTION'])]
df = df[pd.notnull(df['CUSTOMERCODE'])]
col = ['CUSTOMERCODE', 'DESCRIPTION']
df = df[col]
df.columns = ['CUSTOMERCODE', 'DESCRIPTION']
df['category_id'] = df['DESCRIPTION'].factorize()[0]
df = df.applymap(str)
X_train, X_test, y_train, y_test = train_test_split(df['CUSTOMERCODE'], df['DESCRIPTION'], random_state=0)
count_vect = CountVectorizer()
count_vect.fit_transform(X_train)
predicted_result = model.predict(count_vect.transform(data))
return predicted_result.tolist()
except Exception as e:
print("exception occured")
error = str(e)
print(error)
logging.info(error)
return error