Skip to content

thumbnailshower

thumbnailshower

Module for ImageThumbnailShower

Classes

ImageThumbnailShower

ImageThumbnailShower(col_count, selectable=True)

Class to show image thumbnails in a gridview in streamlit

Source code in niceml/utilities/thumbnailshower.py
def __init__(self, col_count: int, selectable: bool = True):
    self.col_count = col_count
    self.selectable = selectable
Functions
show_thumbnails
show_thumbnails(image_list, image_ids)

Shows image thumbnails in a gridview component in streamlit

Parameters:

  • image_list (List[Union[ndarray, Image]]) –

    List of images to show

  • image_ids (List[str]) –

    Ids of the images to show

Returns:

  • Optional[int]

    Index of image when an id is selected in the component

Source code in niceml/utilities/thumbnailshower.py
def show_thumbnails(
    self, image_list: List[Union[np.ndarray, Image.Image]], image_ids: List[str]
) -> Optional[int]:
    """Shows image thumbnails in a gridview component in streamlit

    Args:
        image_list: List of images to show
        image_ids: Ids of the images to show

    Returns:
        Index of image when an id is selected in the component
    """
    columns = st.columns(self.col_count)
    selection_idx: Optional[int] = None
    for idx, image in enumerate(image_list):
        cur_col = columns[idx % self.col_count]
        cur_id = image_ids[idx]
        caption = None if self.selectable else cur_id
        cur_col.image(image, use_column_width=True, caption=caption)
        if self.selectable and cur_col.button(cur_id):
            selection_idx = idx
    return selection_idx