Slackbot
10/24/2022, 10:55 PMTiago Melo
10/24/2022, 10:56 PMAaron Pham
10/25/2022, 1:12 AMdocker run -it --rm -p 3000:3000 container:tag bash
cd /home/bentoml/bento/ && ls -rthlaTiago Melo
10/25/2022, 1:27 PMTiago Melo
10/25/2022, 1:28 PMTiago Melo
10/25/2022, 2:14 PMTiago Melo
10/25/2022, 2:16 PMbentoml build command. To solve that, I did a manual copy from my filesystem moving the model folder to a bentos folder. Thenk I ran the containerize command and then I worked for me. Thanks @Aaron PhamAaron Pham
10/25/2022, 4:27 PMTiago Melo
10/25/2022, 5:06 PMimport bentoml
from bentoml._<http://internal.io|internal.io>_descriptors import NumpyNdarray
import mlflow
import json
import pickle
import pandas as pd
import numpy as np
from sklearn import svm
from sklearn.manifold import LocallyLinearEmbedding
from sklearn.model_selection import train_test_split
from <http://bentoml.io|bentoml.io> import JSON
from pydantic import BaseModel, ValidationError, validator
from validation import ModelFeatures
from artifacts_load import load_param, load_encoder
from data_preprocess import _zscore, create_model_input_dataframe
from cashout_runnable import CashoutRunnable
bento_model = bentoml.mlflow.get('allow_list:latest')
artifacts_path = bento_model.path_of(bentoml.mlflow.MLFLOW_MODEL_FOLDER)
bento_model_runner=<http://bento_model.to|bento_model.to>_runner()
cashout_model = mlflow.xgboost.load_model(artifacts_path)
cashout_runner = bentoml.Runner(
runnable_class=CashoutRunnable,
runnable_init_params=dict({'cashout_model': cashout_model}),
name="cashout_runner")
svc = bentoml.Service('allow_list', runners=[cashout_runner])
current_city_encoder = load_encoder('current_city_encoder.pickle', artifacts_path)
device_status_encoder = load_encoder('device_status_encoder.pickle', artifacts_path)
device_type_encoder = load_encoder('device_type_encoder.pickle', artifacts_path)
operation_type_encoder = load_encoder('operation_type_encoder.pickle', artifacts_path)
owner_type_encoder = load_encoder('owner_type_encoder.pickle', artifacts_path)
json_params = load_param('base_params.json', artifacts_path)
@svc.api(input=JSON(pydantic_model=ModelFeatures), output=JSON())
def classify(input_series: ModelFeatures) -> json:
df_parsed = create_model_input_dataframe(input_series.dict(), current_city_encoder,device_status_encoder,device_type_encoder,operation_type_encoder,owner_type_encoder,json_params)
df_to_model = df_parsed[json_params["training"]["features"]]
df_to_model = df_to_model.astype({'account_amount_zscore':'float', 'account_amount_zscore_robust':'float', 'account_daily_amount_zscore':'float', 'account_daily_amount_zscore_robust':'float', 'account_daily_n_transactions_zscore':'float', 'account_daily_n_transactions_zscore_robust':'float'})
# result = cashout_model.predict_proba(df_to_model) # No runner
# result = bento_model_runner.predict.run(df_to_model) # With runner
result = cashout_runner.predict_proba.run(df_to_model) # Custom runner
return {'RESULT':result}