Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,27 +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 |
-
@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}"
|
29 |
-
st.sidebar.image(image, caption=f"{img.name} {img.size / 1024.0:.1f} KB", width=40, key=image_key)
|
30 |
-
st.sidebar.checkbox(f"Select {img.name}", value=False, key=checkbox_key)
|
31 |
-
|
32 |
-
# Collect selected images based on checkbox input
|
33 |
selected_images = []
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
if st.button("Predict Emotions") and selected_images:
|
42 |
if len(selected_images) == 2:
|
@@ -75,4 +61,5 @@ if st.button("Predict Emotions") and selected_images:
|
|
75 |
st.image(selected_images[i], caption=f"Predicted emotion: {predicted_emotion}", use_column_width=True)
|
76 |
st.write(f"Emotion Scores for #{i+1} Image")
|
77 |
st.write(f"{predicted_emotion}: {result[0]['score']:.4f}")
|
78 |
-
st.write(f"Original File Name: {
|
|
|
|
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 |
selected_images = []
|
20 |
+
if uploaded_images:
|
21 |
+
for img in uploaded_images:
|
22 |
+
image = Image.open(img)
|
23 |
+
selected = st.sidebar.checkbox(f"{img.name} {img.size / 1024.0:.1f} KB", value=False, key=img.name)
|
24 |
+
if selected:
|
25 |
+
selected_images.append(image)
|
26 |
|
27 |
if st.button("Predict Emotions") and selected_images:
|
28 |
if len(selected_images) == 2:
|
|
|
61 |
st.image(selected_images[i], caption=f"Predicted emotion: {predicted_emotion}", use_column_width=True)
|
62 |
st.write(f"Emotion Scores for #{i+1} Image")
|
63 |
st.write(f"{predicted_emotion}: {result[0]['score']:.4f}")
|
64 |
+
st.write(f"Original File Name: {selected_images[i].filename}") # Display original file name
|
65 |
+
|