classBaseHandler(abc.ABC):defpreprocess(self,data:object,parameters:object=None):returndata# (1)defpostprocess(self,data:object,parameters:object=None):returndata# (2)defpredict(self,data:object):ifnotgetattr(self,"model",None):raiseException("Model is not loaded.")predict_func=(# (3)getattr(self.model,self.entrypoint)ifself.entrypointelseself.model)returnpredict_func(data)@abc.abstractmethoddefload_model(self):returnNotImplemented# (4)
classPickleHandler(BaseHandler):"""Pickle Handler for Models Saved through Pickle"""defload_model(self):ifnotgetattr(self,"model_path",None):raiseException("Model path not provided.")withopen(self.model_path,"rb")asf:returnpickle.load(f)