landingai.utils
Module for common utility functions.
load_api_credential(api_key=None)
Load API credential from different sources.
Parameters
api_key: The API key argument to be passed in, by default None. The API key can be provided as arguments or loaded from the environment variables or .env file. The api key loading priority is: arguments > environment variables > .env file.
Returns
APIKey An APIKey (v2 key) instance.
Source code in landingai/utils.py
serialize_image(image)
Serialize the input image into bytes of an image file.
The image file encoding format is set to "JPEG" for optimal latency.
For RGBA images, the encoding format will be PNG
to preserve transparency.
For palettized image, i.e. mode P
or PA
, the image will be converted to RGB before encoding.
In addition, the image file encoding format can be overwritten by the environment variable DEFAULT_IMAGE_SERIALIZATION_FORMAT
.
Supported image serialization formats are: JPEG, PNG, BMP.