devo_ml.modelmanager.downloader#

Available downloaders to store model files.

DownloaderCallable#

Signature type for callable downloaders.

alias of Callable[[dict], str]

get_default_downloader()[source]#

Returns the default downloader used.

Return type:

Downloader

Returns:

The default downloader

get_image_bytes(image)[source]#

Gets the bytes of an image.

An image must have the image key with the base 64 encoded image.

Parameters:

image (dict) – The image to get bytes

Raises:

ValueError – if no image key or image key is empty.

Return type:

bytes

Returns:

The bytes of the image

class Downloader[source]#

An interface to downloaders.

Any downloader must be a callable with the DownloaderCallable signature, receiving a model and returns an identification of the download of the model as a string.

abstract __call__(model)[source]#

Subclasses must implement this method to client be able to calling it as a function.

The representation of a model is a dict with this minimal shape:

{
    "name": <name>,
    "engine": <a_valid_engine>,
    "image": {
        "image": <base64_encoded_image>
        ...
    }
    ...
}
Parameters:

model (dict) – The model to download its file

Return type:

str

Returns:

The identification of the download of the model

class FileSystemDownloader(path)[source]#

A downloader capable of writing file of model to the file system.

__init__(path)[source]#

Creates a FileSystemDownloader object.

Parameters:

path (str | Path) – The path where files will be written

__call__(model)[source]#

Downloads the file associated with the model and writes it in downloader path.

The file name will be the model name plus the inferred extension from the engine. The extension will be empty if it can not infer, e.g: if there is no extension associated to the engine.

Parameters:

model (dict) – The model to download its file

Raises:
  • ValueError – If model has invalid or empty keys for name, engine or image

  • OSError – If there is a problem writing the file to path

Return type:

str

Returns:

The absolute path of file written