question

SenthilMuruganRAMACHANDRAN-7389 avatar image
0 Votes"
SenthilMuruganRAMACHANDRAN-7389 asked SenthilMuruganRAMACHANDRAN-7389 edited

The request failed with status code: 502 error while consuming the model deployed

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
azure-machine-learning
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sorry I can not open you .py file, could you please share the guidance/ code sample you are following? Thanks.


Regards,
Yutong

0 Votes 0 ·

Hi, I have updated my post with the score.py code, Yutong.

0 Votes 0 ·

0 Answers