def _create_prediction_endpoint(<EOL>self,<EOL>to_numpy=True,<EOL>data_loader=json_numpy_loader,<EOL>preprocessor=lambda x: x,<EOL>input_validation=lambda data: (True, None),<EOL>postprocessor=lambda x: x,<EOL>make_serializable_post=True):
<EOL>predict = self.predict<EOL>logger = self.app.logger<EOL>class Predictions(Resource):<EOL><INDENT>@staticmethod<EOL>def post():<EOL><INDENT>try:<EOL><INDENT>data = data_loader()<EOL><DEDENT>except Exception as e:<EOL><INDENT>return exception_log_and_respond(e, logger, '<STR_LIT>', <NUM_LIT>)<EOL><DEDENT>try:<EOL><INDENT>if hasattr(preprocessor, '<STR_LIT>'):<EOL><INDENT>for preprocessor_step in preprocessor:<EOL><INDENT>data = preprocessor_step(data)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>data = preprocessor(data)  <EOL><DEDENT>data = np.array(data) if to_numpy else data  <EOL><DEDENT>except Exception as e:<EOL><INDENT>return exception_log_and_respond(e, logger, '<STR_LIT>', <NUM_LIT>)<EOL><DEDENT>validation_pass, validation_reason = input_validation(data)<EOL>if not validation_pass:<EOL><INDENT>validation_message = '<STR_LIT>'.format(validation_reason)<EOL>logger.error(validation_message)<EOL>logger.debug('<STR_LIT>'.format(data))<EOL>return make_response(validation_message, <NUM_LIT>)<EOL><DEDENT>try:<EOL><INDENT>prediction = predict(data)<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.debug('<STR_LIT>'.format(data))<EOL>return exception_log_and_respond(e, logger, '<STR_LIT>', <NUM_LIT>)<EOL><DEDENT>logger.debug(prediction)<EOL>try:<EOL><INDENT>if hasattr(postprocessor, '<STR_LIT>'):<EOL><INDENT>for postprocessor_step in postprocessor:<EOL><INDENT>prediction = postprocessor_step(prediction)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>prediction = postprocessor(prediction)<EOL><DEDENT>if make_serializable_post:<EOL><INDENT>return make_serializable(prediction)<EOL><DEDENT>else:<EOL><INDENT>return prediction<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>return exception_log_and_respond(e, logger, '<STR_LIT>', <NUM_LIT>)<EOL><DEDENT><DEDENT><DEDENT>self.api.add_resource(Predictions, '<STR_LIT>')<EOL>
Create an endpoint to serve predictions.

        Arguments:
            - input_validation (fn): takes a numpy array as input;
                returns True if validation passes and False otherwise
            - data_loader (fn): reads flask request and returns data preprocessed to be
                used in the `predict` method
            - postprocessor (fn): transforms the predictions from the `predict` method