def create_token_highlights(
    tokens: List[str], weights: List[float], c_map: Optional[Union[str, Callable]] = "viridis"
) -> str:
    """
    Generates an HTML string with tokens highlighted based on the corresponding weights using a color map.

    Args:
        tokens: List of tokens to highlight.
        weights: List of weights corresponding to each token.
        c_map: Optional color map to use for highlighting. Can be a string (name of a matplotlib colormap)
                    or a callable that returns an RGB tuple

    Returns:
        An HTML string with the tokens highlighted.

    Raises:
        ValueError: If the length of tokens and weights is not the same.
        ValueError: If tokens or weights are empty.
        TypeError: If c_map is not a string or a callable.

    Examples:
        >>> from argilla_v1.client.feedback.utils import create_token_highlights
        >>> tokens = ["This", "is", "a", "test"]
        >>> weights = [0.1, 0.2, 0.3, 0.4]
        >>> html = create_token_highlights(tokens, weights)
        >>> html = create_token_highlights(tokens, weights, c_map='viridis')
        >>> html = create_token_highlights(tokens, weights, c_map=custom_RGB)
    """
    require_dependencies("matplotlib")
    import matplotlib.pyplot as plt
    from matplotlib.colors import rgb2hex

    if len(tokens) != len(weights):
        raise ValueError("Length of tokens and weights must be the same.")

    if not tokens or not weights:
        raise ValueError("Token or weight lists must not be empty.")

    max_weight = max(weights)
    min_weight = min(weights)
    normalized_weights = [
        (w - min_weight) / (max_weight - min_weight) if max_weight != min_weight else 0 for w in weights
    ]

    html_str = ["<p>"]
    for token, weight in zip(tokens, normalized_weights):
        if weight == 0:
            html_str.append(f"{token} ")
            continue

        rgba = None

        if callable(c_map):
            rgba = c_map(weight)

        elif isinstance(c_map, str):
            cmap = plt.get_cmap(c_map)
            rgba = cmap(weight)[:3]

        else:
            raise TypeError("c_map must be either a string or a function.")

        hex_color = rgb2hex(rgba)
        html_str.append(f'<span style="background-color: {hex_color}">{token}</span> ')

    html_str.append("</p>")
    return "".join(html_str)

    Generates an HTML string with tokens highlighted based on the corresponding weights using a color map.

    Args:
        tokens: List of tokens to highlight.
        weights: List of weights corresponding to each token.
        c_map: Optional color map to use for highlighting. Can be a string (name of a matplotlib colormap)
                    or a callable that returns an RGB tuple

    Returns:
        An HTML string with the tokens highlighted.

    Raises:
        ValueError: If the length of tokens and weights is not the same.
        ValueError: If tokens or weights are empty.
        TypeError: If c_map is not a string or a callable.

    Examples:
        >>> from argilla_v1.client.feedback.utils import create_token_highlights
        >>> tokens = ["This", "is", "a", "test"]
        >>> weights = [0.1, 0.2, 0.3, 0.4]
        >>> html = create_token_highlights(tokens, weights)
        >>> html = create_token_highlights(tokens, weights, c_map='viridis')
        >>> html = create_token_highlights(tokens, weights, c_map=custom_RGB)
    
argilla-v1/src/argilla_v1/client/feedback/utils/html_utils.py