API
InferlessPythonModel Class
The class called ‘InferlessPythonModel’ is the entrypoint for you ML code. This class has three methods: ‘initialize’, ‘infer’, and ‘finalize’. Let’s go through each method and explain their purpose, signature, and return types.
‘initialize’ method:
- Purpose: This method is responsible for initializing the model and setting up the necessary components.
- Signature: The method takes in one parameter, self, which refers to the instance of the class. It doesn’t have any other parameters.
- Return type: This method doesn’t return anything (None).
‘infer’ method:
- Purpose: This method performs the inference process using the initialized model. It takes in an input dictionary containing a “prompt” key, and it generates an image based on the provided prompt.
- Signature: The method takes in two parameters: self (referring to the instance of the class) and inputs (a dictionary containing the input data).
- Return type: The method returns a dictionary with a single key-value pairs.
‘finalize’ method:
- Purpose: This method is responsible for cleaning up and finalizing the model. It sets the pipe attribute to None.
- Signature: The method takes in one parameter, self, which refers to the instance of the class. It doesn’t have any other parameters.
- Return type: This method doesn’t return anything (None).