Created
July 10, 2022 15:58
-
-
Save asehmi/4aa2af0bf5256ac389f56c0963d00109 to your computer and use it in GitHub Desktop.
Multi-column image grid with Streamlit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import cycle | |
import streamlit as st | |
num_cols = int(st.sidebar.number_input('Number columns', 1, 7, 3, 1)) | |
img_w = int(st.sidebar.number_input('Image width', 50, 500, 150, 10)) | |
images = { | |
'https://unsplash.com/photos/-YHSwy6uqvk/download?force=true&w=640': 'Feast', | |
'https://unsplash.com/photos/UC0HZdUitWY/download?force=true&w=640': 'Mixed Grill', | |
'https://unsplash.com/photos/kcA-c3f_3FE/download?force=true&w=640': 'Tofu Salad', | |
'https://unsplash.com/photos/eeqbbemH9-c/download?force=true&w=640': 'Pancake Stack', | |
'https://unsplash.com/photos/MqT0asuoIcU/download?force=true&w=640': 'Hawaiian Chicken Pizza Smoked', | |
'https://unsplash.com/photos/ZuIDLSz3XLg/download?force=true&w=640': 'Mediterranean Salad', | |
'https://unsplash.com/photos/Mzy-OjtCI70/download?force=true&w=640': 'Delicious cake with pistachio and raspberries', | |
'https://unsplash.com/photos/fdlZBWIP0aM/download?force=true&w=640': 'Avocado and Egg Toast', | |
'https://unsplash.com/photos/awj7sRviVXo/download?force=true&w=640': 'Meal with salmon and zucchini', | |
} | |
cols = cycle(st.columns(num_cols)) | |
for img, caption in images.items(): | |
next(cols).image(img, width=img_w, output_format='auto', caption=caption) |
Author
asehmi
commented
Jul 10, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment