import importlib


def get_model_function(model_type):
    """
    Get tensorflow function of the model to be applied to the input tensor.
    For instance "unet.softmax_unet" will return the softmax_unet function
    in the "unet.py" submodule of the current module (spleeter.model).

    Params:
    - model_type: str
    the relative module path to the model function.

    Returns:
    A tensorflow function to be applied to the input tensor to get the
    multitrack output.
    """
    relative_path_to_module = ".".join(model_type.split(".")[:-1])
    model_name = model_type.split(".")[-1]
    main_module = ".".join((__name__, "functions"))
    path_to_module = f"{main_module}.{relative_path_to_module}"
    module = importlib.import_module(path_to_module)
    model_function = getattr(module, model_name)
    return model_function