xtlyxt commited on
Commit
8daba23
·
verified ·
1 Parent(s): 34951bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -16,9 +16,13 @@ st.write(f"{x} squared is {x * x}")
16
  uploaded_images = st.file_uploader("Upload images", type=["jpg", "png"], accept_multiple_files=True)
17
 
18
  # Display thumbnail images alongside file names and sizes in the sidebar
 
 
 
 
19
  if uploaded_images:
20
  for idx, img in enumerate(uploaded_images):
21
- image = Image.open(img)
22
  # Generate unique keys for image display and checkbox
23
  image_key = f"{img.name}_image_{idx}"
24
  checkbox_key = f"{img.name}_checkbox_{idx}"
@@ -32,7 +36,7 @@ for idx, img in enumerate(uploaded_images):
32
  checkbox_key = f"{img.name}_checkbox_{idx}"
33
  selected = st.sidebar.checkbox(f"Select {img.name}", value=False, key=checkbox_key)
34
  if selected:
35
- selected_images.append(Image.open(img))
36
 
37
  if st.button("Predict Emotions") and selected_images:
38
  if len(selected_images) == 2:
 
16
  uploaded_images = st.file_uploader("Upload images", type=["jpg", "png"], accept_multiple_files=True)
17
 
18
  # Display thumbnail images alongside file names and sizes in the sidebar
19
+ @st.cache
20
+ def load_image(img):
21
+ return Image.open(img)
22
+
23
  if uploaded_images:
24
  for idx, img in enumerate(uploaded_images):
25
+ image = load_image(img)
26
  # Generate unique keys for image display and checkbox
27
  image_key = f"{img.name}_image_{idx}"
28
  checkbox_key = f"{img.name}_checkbox_{idx}"
 
36
  checkbox_key = f"{img.name}_checkbox_{idx}"
37
  selected = st.sidebar.checkbox(f"Select {img.name}", value=False, key=checkbox_key)
38
  if selected:
39
+ selected_images.append(load_image(img))
40
 
41
  if st.button("Predict Emotions") and selected_images:
42
  if len(selected_images) == 2: