Update app.py
Browse files
app.py
CHANGED
@@ -54,21 +54,25 @@ def emotionAnalysis(message, face):
|
|
54 |
face_timestamp = datetime.now().astimezone().strftime(localFormat)
|
55 |
|
56 |
if face is None:
|
57 |
-
face_emotion = "
|
58 |
-
|
59 |
-
face_dataDict["Time"].append(face_timestamp)
|
60 |
-
face_dataDict["Emotion"].append(face_emotion)
|
61 |
-
face_dataDict["Confidence Score"].append(0.0)
|
62 |
else:
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
# Return both the text result and the updated plot
|
74 |
return f"Text: {text_emotion} | Face: {face_emotion}", displayResults()
|
|
|
54 |
face_timestamp = datetime.now().astimezone().strftime(localFormat)
|
55 |
|
56 |
if face is None:
|
57 |
+
face_emotion = "No image"
|
58 |
+
face_score = 0.0
|
|
|
|
|
|
|
59 |
else:
|
60 |
+
try:
|
61 |
+
img_rgb = cv2.cvtColor(face, cv2.COLOR_BGR2RGB)
|
62 |
+
result = face_emotion_detector.top_emotion(img_rgb)
|
63 |
+
if result is None:
|
64 |
+
face_emotion = "No face detected"
|
65 |
+
face_score = 0.0
|
66 |
+
else:
|
67 |
+
face_emotion, face_score = result
|
68 |
+
except Exception as e:
|
69 |
+
face_emotion = "Error processing image"
|
70 |
+
face_score = 0.0
|
71 |
+
|
72 |
+
# Store facial emotion data for plotting
|
73 |
+
face_dataDict["Time"].append(face_timestamp)
|
74 |
+
face_dataDict["Emotion"].append(face_emotion)
|
75 |
+
face_dataDict["Confidence Score"].append(face_score)
|
76 |
|
77 |
# Return both the text result and the updated plot
|
78 |
return f"Text: {text_emotion} | Face: {face_emotion}", displayResults()
|