Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from PIL import Image
|
|
9 |
st.title("Your Emotions? Or Nah?")
|
10 |
# st.title("Hot Dog? Or Not?")
|
11 |
|
12 |
-
file_name = st.file_uploader("Upload a photo of your face
|
13 |
# file_name = st.file_uploader("Upload a hot dog candidate image")
|
14 |
|
15 |
if file_name is not None:
|
@@ -18,18 +18,29 @@ if file_name is not None:
|
|
18 |
|
19 |
# capture image
|
20 |
image = Image.open(file_name)
|
21 |
-
|
|
|
22 |
col1.image(image, use_column_width=True)
|
23 |
|
24 |
-
# capture image data for
|
25 |
image_data = np.array(image)
|
26 |
-
# capture predictions from deepface
|
27 |
-
predictions = DeepFace.analyze(image_data, actions=['emotion'])
|
28 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
#
|
31 |
col2.header("Emotion Probabilities")
|
32 |
-
#
|
33 |
-
for
|
34 |
-
|
35 |
-
col2.subheader(f"{emotion}")
|
|
|
9 |
st.title("Your Emotions? Or Nah?")
|
10 |
# st.title("Hot Dog? Or Not?")
|
11 |
|
12 |
+
file_name = st.file_uploader("Upload a photo of your face")
|
13 |
# file_name = st.file_uploader("Upload a hot dog candidate image")
|
14 |
|
15 |
if file_name is not None:
|
|
|
18 |
|
19 |
# capture image
|
20 |
image = Image.open(file_name)
|
21 |
+
|
22 |
+
# display image in left column
|
23 |
col1.image(image, use_column_width=True)
|
24 |
|
25 |
+
# capture image data for face analysis
|
26 |
image_data = np.array(image)
|
27 |
+
# capture predictions from deepface emotion model
|
28 |
+
predictions = DeepFace.analyze(image_data, actions=['emotion'])
|
29 |
+
# ensure only the main prediction object is processed,
|
30 |
+
if len(predictions) > 1:
|
31 |
+
# when more than one face is detected by the backend,
|
32 |
+
faces = [(face, face['region']['w'] * face['region']['h']) for face in predictions]
|
33 |
+
# by using the predictions connected to the largest bounding box
|
34 |
+
new_predictions = sorted(faces, key=lambda x: x[1], reverse=True)[0][0]
|
35 |
+
emotion_dict = new_predictions['emotion']
|
36 |
+
else:
|
37 |
+
emotion_dict = predictions['emotion']
|
38 |
+
# capture desired prediction data
|
39 |
+
emotions = list(emotion_dict.keys())
|
40 |
+
probabilities = list(emotion_dict.values())
|
41 |
|
42 |
+
# display in the right column...
|
43 |
col2.header("Emotion Probabilities")
|
44 |
+
# ...each emotion category and its probability
|
45 |
+
for i in range(len(emotions)):
|
46 |
+
col2.subheader(f"{emotions[i]}: {probabilities[i]:.2f}%")
|
|