How to use the bentoml.api function in bentoml

To help you get started, we’ve selected a few bentoml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bentoml / BentoML / tests / test_service.py View on Github external
        @bentoml.api(ImageHandler)
        def test(self, image):
            return image
github bentoml / BentoML / tests / test_save_and_load.py View on Github external
    @bentoml.api(DataframeHandler)
    def test(self, df):
        return df
github bentoml / BentoML / tests / test_service.py View on Github external
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")
github bentoml / BentoML / tests / handlers / test_fastai_image_handler.py View on Github external
        @bentoml.api(FastaiImageHandler)
        def predict(self, image):
            return list(image.shape)
github bentoml / BentoML / tests / utils.py View on Github external
    @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)
github bentoml / BentoML / tests / test_service_env.py View on Github external
        @bentoml.api(DataframeHandler)
        def predict(self, df):
            return df
github bentoml / BentoML / guides / deployment / deploy-with-sagemaker / sentiment_lr_model.py View on Github external
    @bentoml.api(DataframeHandler, typ='series')
    def predict(self, series):
        """
        predict expects pandas.Series as input
        """        
        return self.artifacts.sentiment_lr.predict(series)
github bentoml / BentoML / guides / deployment / deploy-with-serverless / sentiment_lr_model.py View on Github external
    @bentoml.api(DataframeHandler, typ='series')
    def predict(self, series):
        """
        predict expects pandas.Series as input
        """        
        return self.artifacts.model.predict(series)
github bentoml / BentoML / examples / sklearn-sentiment-clf / sentiment_lr_model.py View on Github external
    @bentoml.api(DataframeHandler, typ='series')
    def predict(self, series):
        """
        predict expects pandas.Series as input
        """        
        return self.artifacts.sentiment_lr.predict(series)
github bentoml / BentoML / examples / keras-fashion-mnist / keras_fashion_mnist.py View on Github external
    @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]