Update app.py
Browse files
app.py
CHANGED
@@ -53,25 +53,24 @@ def emotionAnalysis(message, face):
|
|
53 |
|
54 |
face_timestamp = datetime.now().astimezone().strftime(localFormat)
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
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
|
|
|
53 |
|
54 |
face_timestamp = datetime.now().astimezone().strftime(localFormat)
|
55 |
|
56 |
+
# Initialize with default values
|
57 |
+
face_emotion = "No image" # Default value
|
58 |
+
face_score = 0.0
|
59 |
+
|
60 |
+
if face is not None:
|
61 |
try:
|
62 |
img_rgb = cv2.cvtColor(face, cv2.COLOR_BGR2RGB)
|
63 |
result = face_emotion_detector.top_emotion(img_rgb)
|
64 |
+
if result is not None: # Only update if we got a valid result
|
|
|
|
|
|
|
65 |
face_emotion, face_score = result
|
66 |
+
else:
|
67 |
+
face_emotion = "No face detected"
|
68 |
except Exception as e:
|
69 |
+
face_emotion = f"Error processing image: {str(e)}"
|
|
|
70 |
|
71 |
# Store facial emotion data for plotting
|
72 |
face_dataDict["Time"].append(face_timestamp)
|
73 |
+
face_dataDict["Emotion"].append(face_emotion) # Now face_emotion will always be a string
|
74 |
face_dataDict["Confidence Score"].append(face_score)
|
75 |
|
76 |
# Return both the text result and the updated plot
|