Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,26 +15,20 @@ st.title("Emotion Recognition with vit-face-expression")
|
|
15 |
x = st.slider('Select a value')
|
16 |
st.write(f"{x} squared is {x * x}")
|
17 |
|
18 |
-
# Upload
|
19 |
-
uploaded_images = st.file_uploader("Upload
|
20 |
|
21 |
-
if
|
22 |
# Open the uploaded images
|
23 |
images = [Image.open(img) for img in uploaded_images]
|
24 |
|
25 |
# Predict emotion for each image using the pipeline
|
26 |
results = [pipe(image) for image in images]
|
27 |
|
28 |
-
# Display images and predicted emotions
|
29 |
-
col1, col2 = st.columns(2)
|
30 |
-
for i in range(2):
|
31 |
-
predicted_class = results[i][0]["label"]
|
32 |
-
predicted_emotion = predicted_class.split("_")[-1].capitalize()
|
33 |
-
col = col1 if i == 0 else col2
|
34 |
-
col.image(images[i], caption=f"Predicted emotion: {predicted_emotion}", use_column_width=True)
|
35 |
-
|
36 |
-
# Display the scores for each image
|
37 |
-
st.write("Emotion Scores:")
|
38 |
for i, result in enumerate(results):
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
15 |
x = st.slider('Select a value')
|
16 |
st.write(f"{x} squared is {x * x}")
|
17 |
|
18 |
+
# Upload images
|
19 |
+
uploaded_images = st.file_uploader("Upload images", type=["jpg", "png"], accept_multiple_files=True)
|
20 |
|
21 |
+
if st.button("Predict Emotions") and uploaded_images:
|
22 |
# Open the uploaded images
|
23 |
images = [Image.open(img) for img in uploaded_images]
|
24 |
|
25 |
# Predict emotion for each image using the pipeline
|
26 |
results = [pipe(image) for image in images]
|
27 |
|
28 |
+
# Display images and predicted emotions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
for i, result in enumerate(results):
|
30 |
+
predicted_class = result[0]["label"]
|
31 |
+
predicted_emotion = predicted_class.split("_")[-1].capitalize()
|
32 |
+
st.image(images[i], caption=f"Predicted emotion: {predicted_emotion}", use_column_width=True)
|
33 |
+
st.write(f"Emotion Scores for Image {i+1}:")
|
34 |
+
st.write(f"{predicted_emotion}: {result[0]['score']:.4f}")
|