echung682 commited on
Commit
7e6b3cc
·
verified ·
1 Parent(s): 11f7576

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
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 = "Unreadable"
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
- # Capture and process facial emotion
64
- img_rgb = cv2.cvtColor(face, cv2.COLOR_BGR2RGB)
65
-
66
- face_emotion, face_score = face_emotion_detector.top_emotion(img_rgb)
67
-
68
- # Store facial emotion data for plotting
69
- face_dataDict["Time"].append(face_timestamp)
70
- face_dataDict["Emotion"].append(face_emotion)
71
- face_dataDict["Confidence Score"].append(face_score)
 
 
 
 
 
 
 
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()