def pil_to_data_uri(image_object: Optional["Image"]) -> Optional[str]:
    """Convert a PIL image to a base64 data URI string.
    Parameters:
        image_object (Image): The PIL image to convert to a base64 data URI.
    Returns:
        str: The data URI string.
    """
    if image_object is None:
        return None
    if not isinstance(image_object, Image.Image):
        raise ValueError("The image_object must be a PIL Image object.")

    image_format = image_object.format
    if image_format is None:
        image_format = "PNG"
        warnings.warn("The image format is not set. Defaulting to PNG.", UserWarning)

    try:
        buffered = io.BytesIO()
        image_object.save(buffered, format=image_format)
    except Exception as e:
        raise ValueError("An error occurred while saving the image binary to buffer") from e

    try:
        img_str = base64.b64encode(buffered.getvalue()).decode()
        mimetype = f"image/{image_format.lower()}"
        data_uri = f"data:{mimetype};base64,{img_str}"
    except Exception as e:
        raise ValueError("An error occurred while converting the image binary to base64") from e

    return data_uri
Convert a PIL image to a base64 data URI string.
    Parameters:
        image_object (Image): The PIL image to convert to a base64 data URI.
    Returns:
        str: The data URI string.
    
argilla/src/argilla/_helpers/_media.py