Exemplo n.º 1
0
    api_version='v1',  # The version of the model. Returned
    # to client in the prediction response.
    # Required.
    #
    preprocessor=preprocessor,  # preprocessor.process() is
    # called on the POST request data
    # before predicting. Optional.
    #
    postprocessor=Postprocessor(),  # postprocessor.process() is
    # called on the model's predictions before
    # returning to user. Optional.
    #
    feature_schema=feature_schema,  # The input schema is used to validate
    # the payload of the POST request.
    # Optional.
    validate_request_data=True,  # Whether to validate the request data.
    #
    batch_prediction=True  # Whether the API will accept an array of
    # JSON objects to predict on or a single
    # JSON object only.
)

# The model app is simply a wrapper around the `flask.Flask` object.
model_app = ModelApp([prediction_service])

if __name__ == '__main__':
    # you can run this with `gunicorn app:model_app`, or
    # simply execute this script with Python and send POST requests
    # to localhost:8000/supa-dupa-model/prediction/
    model_app.run(port=8000)
Exemplo n.º 2
0
        raise PorterException('input cannot include zeros', code=422)


input_schema = sc.Array(item_type=sc.Number(), reference_name='InputSchema')
output_schema = sc.Number(reference_name='OutputSchema')
service_kw = dict(input_schema=input_schema,
                  output_schema=output_schema,
                  validate_request_data=True)

sum_service = FunctionService('sum',
                              sum,
                              name='math',
                              api_version='v1',
                              **service_kw)
prod_service = FunctionService('prod',
                               prod,
                               name='math',
                               api_version='v1',
                               additional_checks=check_for_zeros,
                               **service_kw)

app = ModelApp(
    [sum_service, prod_service],
    name='FunctionService Example',
    description=
    'Expose arbitrary callable functions by subclassing BaseService.',
    expose_docs=True)

if __name__ == '__main__':
    app.run()
Exemplo n.º 3
0

"""
These are just some convenience functions to test the example.
"""


class Shhh:
    """Silence flask logging."""

    def __init__(self):
        self.devnull = open(os.devnull, 'w')
        self.stdout = sys.stdout
        self.stderr = sys.stderr

    def __enter__(self):
        sys.stdout = self.devnull
        sys.stderr = self.devnull

    def __exit__(self, *exc):
        sys.stdout = self.stdout
        sys.stderr = self.stderr



if __name__ == '__main__':
    print('http://localhost:5000/')
    with Shhh():
        model_app.run()