Devops-hestabit commited on
Commit
6b6c787
·
verified ·
1 Parent(s): e04d5f6

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +13 -2
handler.py CHANGED
@@ -57,6 +57,10 @@ class EndpointHandler():
57
 
58
  # Extract MFCC features
59
  mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=30)
 
 
 
 
60
 
61
  return mfcc
62
 
@@ -65,10 +69,17 @@ class EndpointHandler():
65
  raise
66
 
67
  def perform_emotion_analysis(self, features, emotion_padding=216, depression_padding=2584):
68
- emotion_features = self.get_mfcc_features(features, emotion_padding)
 
 
 
69
  depression_features = self.get_mfcc_features(features, depression_padding)
 
 
 
 
70
  emotion_prediction = self.emotion_model.predict(emotion_features)[0]
71
  emotion_prediction = self.emotion_labels[np.argmax(emotion_prediction)]
 
72
  depression_prediction = self.depression_model.predict(depression_features)[0]
73
- # depression_prediction = "Depressed" if depression_prediction >= 0.5 else "Not Depressed"
74
  return emotion_prediction, depression_prediction
 
57
 
58
  # Extract MFCC features
59
  mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=30)
60
+ if mfcc.shape[1] < 216:
61
+ mfcc = np.pad(mfcc, ((0, 0), (0, 216 - mfcc.shape[1])), mode='constant')
62
+ elif mfcc.shape[1] > 216:
63
+ mfcc = mfcc[:, :216]
64
 
65
  return mfcc
66
 
 
69
  raise
70
 
71
  def perform_emotion_analysis(self, features, emotion_padding=216, depression_padding=2584):
72
+ emotion_features = features[:, :emotion_padding]
73
+ emotion_features = np.expand_dims(emotion_features, axis=-1) # Add channel dimension
74
+ emotion_features = np.expand_dims(emotion_features, axis=0) # Add batch dimension
75
+
76
  depression_features = self.get_mfcc_features(features, depression_padding)
77
+
78
+ print("Emotion model input shape:", self.emotion_model.input_shape)
79
+ print("Emotion features shape:", emotion_features.shape)
80
+
81
  emotion_prediction = self.emotion_model.predict(emotion_features)[0]
82
  emotion_prediction = self.emotion_labels[np.argmax(emotion_prediction)]
83
+
84
  depression_prediction = self.depression_model.predict(depression_features)[0]
 
85
  return emotion_prediction, depression_prediction