webapp1 commited on
Commit
66f7eda
·
verified ·
1 Parent(s): b5d3010

Upload 2 files

Browse files
src/models/audio_classifier.py CHANGED
@@ -214,16 +214,22 @@ class AudioEnsemblePipeline:
214
 
215
  prob_dict = {str(self.classes_[i]): round(float(probs[i]), 4) for i in range(len(self.classes_))}
216
 
217
- high_stress_emotions = ["Stress", "Anxiety", "Depression", "Emotional Distress"]
218
 
219
- # Only sum probabilities for categories that actually exist in self.classes_
220
  stress_prob_sum = 0.0
221
  for e in high_stress_emotions:
222
  if e in self.classes_:
223
  stress_prob_sum += probs[self.classes_.index(e)]
224
-
225
  rms_val = float(feature_vector_195[-1])
226
- stress_intensity = round(float(min(100.0, max(5.0, stress_prob_sum * 85.0 + (rms_val * 60.0)))), 2)
 
 
 
 
 
 
227
 
228
  return {
229
  "predicted_emotion": pred_emotion,
 
214
 
215
  prob_dict = {str(self.classes_[i]): round(float(probs[i]), 4) for i in range(len(self.classes_))}
216
 
217
+ high_stress_emotions = ["Angry", "Fearful", "Sad", "Disgust"]
218
 
219
+ # Safe prob sum calculation checking if classes exist
220
  stress_prob_sum = 0.0
221
  for e in high_stress_emotions:
222
  if e in self.classes_:
223
  stress_prob_sum += probs[self.classes_.index(e)]
224
+
225
  rms_val = float(feature_vector_195[-1])
226
+
227
+ # Reduce the impact of RMS volume so normal speech doesn't get flagged as Stress
228
+ # Default stress relies much more on the predicted probabilities
229
+ base_intensity = stress_prob_sum * 100.0
230
+ volume_penalty = min(20.0, rms_val * 20.0) # Cap volume contribution
231
+
232
+ stress_intensity = round(float(min(100.0, max(5.0, base_intensity + volume_penalty))), 2)
233
 
234
  return {
235
  "predicted_emotion": pred_emotion,
src/models/fusion_engine.py CHANGED
@@ -64,17 +64,17 @@ class LateDecisionFusion:
64
 
65
  # Determine primary stress origin
66
  t_cat = text_result.get("predicted_category", "Normal")
67
- if combined_stress_score < 30.0:
68
  final_category = "Normal"
69
  else:
70
  final_category = t_cat if t_cat != "Normal" else "Stress"
71
 
72
  # Determine clinical risk tier
73
- if combined_stress_score < 30.0:
74
  risk_tier = "Minimal / Normal"
75
  color_code = "green"
76
  action_summary = "No significant psychological stress detected. Emotional tone is balanced."
77
- elif combined_stress_score < 55.0:
78
  risk_tier = f"Mild {final_category}" if final_category not in ["Normal", "Stress", "Calm / Normal"] else "Mild Stress"
79
  color_code = "blue"
80
  action_summary = f"Mild symptoms of {final_category.lower()} observed. Recommended: short breaks and time-management strategies."
@@ -132,10 +132,18 @@ class LateDecisionFusion:
132
  def _single_modality_audio_result(self, audio_result):
133
  score = audio_result.get("acoustic_stress_score", 0.0)
134
  emotion = audio_result.get("predicted_emotion", "Neutral")
135
- cat = "Non-Academic / Vocal Stress" if emotion in ["Angry", "Fearful", "Sad", "Disgust"] else "Calm / Normal"
136
- if score < 30.0:
 
 
 
 
 
 
 
 
137
  tier, color, summary = "Minimal / Normal", "green", "Vocal tone is calm and stable."
138
- elif score < 55.0:
139
  tier, color, summary = "Mild Stress", "blue", f"Slight vocal tension ({emotion.lower()}) observed."
140
  elif score < 80.0:
141
  tier, color, summary = "Moderate Stress", "orange", f"High vocal agitation ({emotion.lower()}) and spectral energy detected."
 
64
 
65
  # Determine primary stress origin
66
  t_cat = text_result.get("predicted_category", "Normal")
67
+ if combined_stress_score < 40.0:
68
  final_category = "Normal"
69
  else:
70
  final_category = t_cat if t_cat != "Normal" else "Stress"
71
 
72
  # Determine clinical risk tier
73
+ if combined_stress_score < 40.0:
74
  risk_tier = "Minimal / Normal"
75
  color_code = "green"
76
  action_summary = "No significant psychological stress detected. Emotional tone is balanced."
77
+ elif combined_stress_score < 60.0:
78
  risk_tier = f"Mild {final_category}" if final_category not in ["Normal", "Stress", "Calm / Normal"] else "Mild Stress"
79
  color_code = "blue"
80
  action_summary = f"Mild symptoms of {final_category.lower()} observed. Recommended: short breaks and time-management strategies."
 
132
  def _single_modality_audio_result(self, audio_result):
133
  score = audio_result.get("acoustic_stress_score", 0.0)
134
  emotion = audio_result.get("predicted_emotion", "Neutral")
135
+
136
+ # Determine category based on emotion or score
137
+ if emotion in ["Angry", "Fearful", "Sad", "Disgust", "Stress", "Anxiety", "Depression", "Emotional Distress"]:
138
+ cat = "Non-Academic / Vocal Stress"
139
+ elif score >= 40.0:
140
+ cat = "Non-Academic / Vocal Stress"
141
+ else:
142
+ cat = "Calm / Normal"
143
+
144
+ if score < 40.0:
145
  tier, color, summary = "Minimal / Normal", "green", "Vocal tone is calm and stable."
146
+ elif score < 60.0:
147
  tier, color, summary = "Mild Stress", "blue", f"Slight vocal tension ({emotion.lower()}) observed."
148
  elif score < 80.0:
149
  tier, color, summary = "Moderate Stress", "orange", f"High vocal agitation ({emotion.lower()}) and spectral energy detected."