flash.core.serve.decorators.expose¶
- flash.core.serve.decorators.expose(inputs, outputs)[source]¶
Expose a function/method via a web API for serving model inference.
The
@expose
decorator has two arguments, inputs and outputs, which describe how the inputs to predict are decoded from the request and how the outputs of predict are encoded to a response.Must decorate one (and only one) method when used within a subclass of
ModelComponent
.- Parameters
inputs¶ (
Dict
[str
,BaseType
]) – accepts a dictionary mapping keys to decorated method parameter names (must be one to one mapping) with values corresponding to an instantiated specification of a Flash Serve Data Type (ie.Number()
,Image()
,Text()
, etc…)outputs¶ (
Dict
[str
,BaseType
]) – accepts a dictionary mapping outputs of the decorated method to keys and data type (similar to inputs). However, unlikeinputs
the output keys are less strict in their names. IF the method returns a dictionary, the keys must match one-to-one. However, if the method returns a sorted sequence (list / tuple) the keys can be arbitrary, so long as no reserved names are used (primarily python keywords). For result sequences, the order in which keys are defined maps to the appropriate element index in the result (ie.key 0 -> sequence[0]
,key 1 -> sequence[1]
, etc.)