Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@bentoml.api(ImageHandler)
def test(self, image):
return image
@bentoml.api(DataframeHandler)
def test(self, df):
return df
def test_custom_api_name():
# these names should work:
bentoml.api(DataframeHandler, api_name="a_valid_name")(lambda x: x)
bentoml.api(DataframeHandler, api_name="AValidName")(lambda x: x)
bentoml.api(DataframeHandler, api_name="_AValidName")(lambda x: x)
bentoml.api(DataframeHandler, api_name="a_valid_name_123")(lambda x: x)
with pytest.raises(InvalidArgument) as e:
bentoml.api(DataframeHandler, api_name="a invalid name")(lambda x: x)
assert str(e.value).startswith("Invalid API name")
with pytest.raises(InvalidArgument) as e:
bentoml.api(DataframeHandler, api_name="123_a_invalid_name")(lambda x: x)
assert str(e.value).startswith("Invalid API name")
with pytest.raises(InvalidArgument) as e:
bentoml.api(DataframeHandler, api_name="a-invalid-name")(lambda x: x)
assert str(e.value).startswith("Invalid API name")
@bentoml.api(FastaiImageHandler)
def predict(self, image):
return list(image.shape)
@bentoml.api(bentoml.handlers.DataframeHandler, input_columns_require=['age'])
def predict(self, df):
"""
predict expects dataframe as input
"""
return self.artifacts.fake_model.predict(df)
@bentoml.api(DataframeHandler)
def predict(self, df):
return df
@bentoml.api(DataframeHandler, typ='series')
def predict(self, series):
"""
predict expects pandas.Series as input
"""
return self.artifacts.sentiment_lr.predict(series)
@bentoml.api(DataframeHandler, typ='series')
def predict(self, series):
"""
predict expects pandas.Series as input
"""
return self.artifacts.model.predict(series)
@bentoml.api(DataframeHandler, typ='series')
def predict(self, series):
"""
predict expects pandas.Series as input
"""
return self.artifacts.sentiment_lr.predict(series)
@api(ImageHandler, pilmode='L')
def predict(self, img):
img = Image.fromarray(img).resize((28, 28))
img = np.array(img.getdata()).reshape((1,28,28,1))
class_idx = self.artifacts.classifier.predict_classes(img)[0]
return class_names[class_idx]