Update app.py
Browse files
app.py
CHANGED
@@ -68,9 +68,8 @@ class CNN1DLSTMAudioClassifier(nn.Module):
|
|
68 |
|
69 |
num_class = 6
|
70 |
model = CNN1DLSTMAudioClassifier(num_class)
|
71 |
-
|
72 |
-
model
|
73 |
-
model = model.to(device)
|
74 |
model.eval()
|
75 |
|
76 |
def preprocess_single_audio(file_path, sample_rate=16000, n_mels=128, n_fft=2048, hop_length=512):
|
@@ -136,13 +135,14 @@ def decode_emotion_prediction(prediction_tensor, label_encoder):
|
|
136 |
|
137 |
return predicted_emotion, confidence
|
138 |
|
|
|
|
|
139 |
|
140 |
def predict(wave):
|
141 |
wave = preprocess_single_audio(wave)
|
142 |
le = LabelEncoder()
|
143 |
le.classes_ = np.array(['Angry', 'Disgusting', 'Fear', 'Happy', 'Neutral', 'Sad'])
|
144 |
wave = wave.unsqueeze(0)
|
145 |
-
wave = wave.to(device)
|
146 |
with torch.no_grad():
|
147 |
prediction = model(wave)
|
148 |
predicted_emotion, confidence = decode_emotion_prediction(prediction, le)
|
|
|
68 |
|
69 |
num_class = 6
|
70 |
model = CNN1DLSTMAudioClassifier(num_class)
|
71 |
+
|
72 |
+
model.load_state_dict(torch.load("best-model-emotion-recognition.bin", weights_only=False))
|
|
|
73 |
model.eval()
|
74 |
|
75 |
def preprocess_single_audio(file_path, sample_rate=16000, n_mels=128, n_fft=2048, hop_length=512):
|
|
|
135 |
|
136 |
return predicted_emotion, confidence
|
137 |
|
138 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
139 |
+
model = model.to(device)
|
140 |
|
141 |
def predict(wave):
|
142 |
wave = preprocess_single_audio(wave)
|
143 |
le = LabelEncoder()
|
144 |
le.classes_ = np.array(['Angry', 'Disgusting', 'Fear', 'Happy', 'Neutral', 'Sad'])
|
145 |
wave = wave.unsqueeze(0)
|
|
|
146 |
with torch.no_grad():
|
147 |
prediction = model(wave)
|
148 |
predicted_emotion, confidence = decode_emotion_prediction(prediction, le)
|