Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import io
|
| 4 |
+
|
| 5 |
+
# Initialize a session state to keep track of images
|
| 6 |
+
if 'images' not in st.session_state:
|
| 7 |
+
st.session_state.images = []
|
| 8 |
+
|
| 9 |
+
# Function to reset images
|
| 10 |
+
def reset_images():
|
| 11 |
+
st.session_state.images = []
|
| 12 |
+
|
| 13 |
+
# Main app function
|
| 14 |
+
def main():
|
| 15 |
+
st.title("Sock Image Uploader")
|
| 16 |
+
|
| 17 |
+
# Image uploader
|
| 18 |
+
uploaded_file = st.file_uploader("Take a picture of your sock and upload it here", type=["jpg", "png"])
|
| 19 |
+
|
| 20 |
+
# If a file is uploaded, process and display it
|
| 21 |
+
if uploaded_file is not None:
|
| 22 |
+
# Convert the file to an image
|
| 23 |
+
image = Image.open(uploaded_file)
|
| 24 |
+
st.session_state.images.append(image)
|
| 25 |
+
|
| 26 |
+
# Display images
|
| 27 |
+
for idx, img in enumerate(st.session_state.images, start=1):
|
| 28 |
+
st.image(img, caption=f"Image {idx}", use_column_width=True)
|
| 29 |
+
|
| 30 |
+
# Reset button
|
| 31 |
+
if st.button('Reset and Start Over'):
|
| 32 |
+
reset_images()
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
main()
|