Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,35 +16,46 @@ 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 img in uploaded_images:
|
21 |
image = Image.open(img)
|
22 |
-
st.sidebar.
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
if len(
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
29 |
+
# Predict emotion for each selected image using the pipeline
|
30 |
+
results = [pipe(image) for image in selected_images]
|
31 |
+
|
32 |
+
# Display images and predicted emotions side by side
|
33 |
+
col1, col2 = st.columns(2)
|
34 |
+
for i in range(2):
|
35 |
+
predicted_class = results[i][0]["label"]
|
36 |
+
predicted_emotion = predicted_class.split("_")[-1].capitalize()
|
37 |
+
col = col1 if i == 0 else col2
|
38 |
+
col.image(selected_images[i], caption=f"Predicted emotion: {predicted_emotion}", use_column_width=True)
|
39 |
+
col.write(f"Emotion Scores: {predicted_emotion}: {results[i][0]['score']:.4f}")
|
40 |
+
col.write(f"Original File Name: {uploaded_images[i].name}") # Display original file name
|
41 |
+
|
42 |
+
# Display the keys and values of all results
|
43 |
+
st.write("Keys and Values of all results:")
|
44 |
+
col1, col2 = st.columns(2)
|
45 |
+
for i, result in enumerate(results):
|
46 |
+
col = col1 if i == 0 else col2
|
47 |
+
col.write(f"Keys and Values of results[{i}]:")
|
48 |
+
for res in result:
|
49 |
+
label = res["label"]
|
50 |
+
score = res["score"]
|
51 |
+
col.write(f"{label}: {score:.4f}")
|
52 |
+
|
53 |
+
else:
|
54 |
+
# Predict emotion for each selected image using the pipeline
|
55 |
+
results = [pipe(image) for image in selected_images]
|
56 |
+
|
57 |
+
# Display images and predicted emotions
|
58 |
+
for i, result in enumerate(results):
|
59 |
+
predicted_class = result[0]["label"]
|
60 |
+
predicted_emotion = predicted_class.split("_")[-1].capitalize()
|
61 |
+
st.image(selected_images[i], caption=f"Predicted emotion: {predicted_emotion}", use_
|