<@URBHE4FML> yes you can in fact embedded two or m...
# ask-for-help
c
@aispace yes you can in fact embedded two or more models into one BentoService, here’s a quick example:
Copy code
import bentoml
from bentoml.handlers import DataframeHandler
from bentoml.artifact import SklearnModelArtifact

@bentoml.artifacts([
    SklearnModelArtifact('model1'),
    SklearnModelArtifact('model2')
]) # defining required artifacts, typically trained models
class IrisClassifier(bentoml.BentoService):

    @bentoml.api(DataframeHandler) # defining prediction service endpoint and expected input format
    def predict_1(self, df):
        # Pre-processing logic and access to trained mdoel artifacts in API function
        return self.artifacts.model1.predict(df)


    @bentoml.api(DataframeHandler) # defining prediction service endpoint and expected input format
    def predict_2(self, df):
        # Pre-processing logic and access to trained mdoel artifacts in API function
        return self.artifacts.model2.predict(df)


# Create a iris classifier service
iris_classifier_service = IrisClassifier()

# Pack it with the newly trained model artifact
iris_classifier_service.pack('model1', clf)
iris_classifier_service.pack('model2', clf)

# Save the prediction service to a BentoService bundle
saved_path = iris_classifier_service.save()