| import streamlit as st |
| from PIL import Image |
|
|
| |
| st.set_page_config(layout="wide") |
|
|
| |
| if 'images' not in st.session_state: |
| st.session_state.images = [] |
|
|
| |
| def reset_images(): |
| |
| st.session_state.images.clear() |
| |
| st.session_state.file_uploader = None |
|
|
| |
| def main(): |
| st.title("Sock Image Uploader") |
|
|
| |
| uploaded_file = st.file_uploader("Take a picture of your sock and upload it here", type=["jpg", "png"], key="file_uploader") |
|
|
| |
| if uploaded_file is not None: |
| |
| image = Image.open(uploaded_file) |
| st.session_state.images.append(image) |
|
|
| |
| cols_per_row = 4 |
| for i in range(0, len(st.session_state.images), cols_per_row): |
| cols = st.columns(cols_per_row) |
| for j in range(cols_per_row): |
| if i + j < len(st.session_state.images): |
| with cols[j]: |
| st.image(st.session_state.images[i + j], caption=f"Image {i + j + 1}", use_column_width=True) |
|
|
| |
| if st.button('Reset and Start Over'): |
| reset_images() |
|
|
| if __name__ == "__main__": |
| main() |
|
|