Skip to main content

A Streamlit custom component for image selection with single and multi-selection support

Project description

streamlit-image-select 🖼️

Fork of streamlit-image-select with multiple selection support.

An image select component for Streamlit.

This custom component works just like st.selectbox but with images. It's a great option if you want to let the user select an example image, e.g. for a computer vision app!

NEW: This fork adds support for selecting multiple images with the allow_multiple parameter.


🏃 Try out the demo app 🏃


Installation

pip install streamlit-image-select

Usage

Single Selection (Original)

from streamlit_image_select import image_select
img = image_select("Label", ["image1.png", "image2.png", "image3.png"])
st.write(img)

Multiple Selection (NEW)

from streamlit_image_select import image_select
imgs = image_select(
    "Select multiple images", 
    ["image1.png", "image2.png", "image3.png"],
    allow_multiple=True
)
st.write(f"Selected {len(imgs)} images")

Parameters

  • label (str): The label shown above the images.
  • images (list): The images to show. Supports local files, URLs, PIL images, and numpy arrays.
  • captions (list of str, optional): Captions to show below images. Defaults to None.
  • index (int or list, optional): Initially selected image(s). For single selection: int. For multiple selection: list of ints. Defaults to 0.
  • use_container_width (bool, optional): Whether to stretch images to container width. Defaults to True.
  • return_value ("original" or "index", optional): Return original objects or indices. Defaults to "original".
  • allow_multiple (bool, optional): Enable multiple selection. Defaults to False.
  • key (str, optional): Component key. Defaults to None.

Returns

  • Single selection (allow_multiple=False): Returns single item (image or index)
  • Multiple selection (allow_multiple=True): Returns list of items (images or indices)

Development

Warning You only need to run these steps if you want to change this component or contribute to its development!

Setup

First, clone the repository:

git clone https://github.com/jrieke/streamlit-image-select.git
cd streamlit-image-select

Install the Python dependencies:

poetry install --dev

And install the frontend dependencies:

cd streamlit_image_select/frontend
npm install

Making changes

To make changes, first go to streamlit_image_select/__init__.py and make sure the variable _RELEASE is set to False. This will make the component use the local version of the frontend code, and not the built project.

Then, start one terminal and run:

cd streamlit_image_select/frontend
npm start

This starts the frontend code on port 3001.

Open another terminal and run:

cp demo/streamlit_app.py .
poetry shell
streamlit run streamlit_app.py

This copies the demo app to the root dir (so you have something to work with and see your changes!) and then starts it. Now you can make changes to the Python or Javascript code in streamlit_image_select and the demo app should update automatically!

If nothing updates, make sure the variable _RELEASE in streamlit_image_select/__init__.py is set to False.

Publishing on PyPI

Switch the variable _RELEASE in streamlit_image_select/__init__.py to True. Increment the version number in pyproject.toml. Make sure the copy of the demo app in the root dir is deleted or merged back into the demo app in demo/streamlit_app.py.

Build the frontend code with:

cd streamlit_image_select/frontend
npm run build

After this has finished, build and upload the package to PyPI:

cd ../..
poetry build
poetry publish

Changelog

0.6.0 (March 28, 2023)

  • Removed st.experimental_memo, which is deprecated.
  • Changed minimum version of Streamlit to 1.19.

0.5.1 (November 20, 2022)

  • Hotfix, forgot to switch the RELEASE variable back to True :wink:

0.5.0 (November 20, 2022)

  • Added return_value parameter to be able to get the index of the selected image.
  • Improved error messages.

0.4.0 (November 20, 2022)

  • Added index parameter to set the initially selected image.
  • Improved input arg checks.

0.3.0 (November 13, 2022)

  • Added use_container_width parameter to customize the width of the component.
  • Made key and use_container_width parameters keyword-only.
  • Refactored CSS classes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

st_img_picker-1.0.1.tar.gz (696.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

st_img_picker-1.0.1-py3-none-any.whl (358.7 kB view details)

Uploaded Python 3

File details

Details for the file st_img_picker-1.0.1.tar.gz.

File metadata

  • Download URL: st_img_picker-1.0.1.tar.gz
  • Upload date:
  • Size: 696.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for st_img_picker-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6b4a69c7d79d8ec5fad09d4d68cd15c9359685c3ea938c2d96990a7c0d5588fb
MD5 0d5c293ec8da8dbe276a32552672904b
BLAKE2b-256 7a3483d2748a90817c1fee76c62607684305390f2f5a4b426a4cc7821c43ece8

See more details on using hashes here.

File details

Details for the file st_img_picker-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: st_img_picker-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 358.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for st_img_picker-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 736753099601821a494d5f15906a635930b894d7d0be211267a448400a50e7f5
MD5 124629620c78c5b75c0ebea29b424b80
BLAKE2b-256 6592b512837b045fc3e61a834e862bdf4a9aacd38fced6b1cd9610fb06317927

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page