import numpy as np
import bentoml
from
bentoml.io import NumpyNdarray, Text
# Define the service class
@bentoml.service(
name="iris_classifier",
runners=[iris_clf_runner],
resources={"cpu": "2"},
traffic={"timeout": 10},
)
class IrisClassifier:
bento_model = bentoml.models.get("iris:latest")
def __init__(self):
self.model = bentoml.mlflow.load_model(self.bento_model)
@bentoml.api(
input=NumpyNdarray.from_sample(np.array([4.9, 3.0, 1.4, 0.2], dtype=np.double)),
output=Text(),
)
async def classify(self, features: np.ndarray) -> str:
with bentoml.monitor("iris_classifier_prediction") as mon:
mon.log(features[0], name="sepal length", role="feature", data_type="numerical")
mon.log(features[1], name="sepal width", role="feature", data_type="numerical")
mon.log(features[2], name="petal length", role="feature", data_type="numerical")
mon.log(features[3], name="petal width", role="feature", data_type="numerical")
results = await iris_clf_runner.predict.async_run([features])
result = results[0]
category = CLASS_NAMES[result]
mon.log(category, name="pred", role="prediction", data_type="categorical")
return category
@bentoml.api(
input=NumpyNdarray.from_sample(np.array([[4.9, 3.0, 1.4, 0.2]], dtype=np.double)),
output=NumpyNdarray(),
)
def predict(self, input_data: np.ndarray) -> np.ndarray:
rv = self.model.predict(input_data)
return np.asarray(rv)
# Initialize the service
svc = IrisClassifier()
if this way works , could you please let me know anyone