Update app.py
Browse files
app.py
CHANGED
|
@@ -17,10 +17,11 @@ def get_emotion(microphone, file_upload, task):
|
|
| 17 |
elif (microphone is None) and (file_upload is None):
|
| 18 |
return "ERROR: You have to either use the microphone or upload an audio file"
|
| 19 |
|
| 20 |
-
|
| 21 |
file = microphone if microphone is not None else file_upload
|
| 22 |
-
|
| 23 |
-
test = feature_extractor(
|
|
|
|
| 24 |
logits = model(**test).logits
|
| 25 |
predicted_ids = torch.argmax(logits, dim=-1)
|
| 26 |
labels = [model.config.id2label[_id] for _id in predicated_ids.tolist()]
|
|
|
|
| 17 |
elif (microphone is None) and (file_upload is None):
|
| 18 |
return "ERROR: You have to either use the microphone or upload an audio file"
|
| 19 |
|
| 20 |
+
model = torch.load('model.pth')
|
| 21 |
file = microphone if microphone is not None else file_upload
|
| 22 |
+
speech, _ = librosa.load(file, sr=16000, mono=True)
|
| 23 |
+
test = feature_extractor(speech, sampling_rate=16000, padding=True, return_tensors="pt" )
|
| 24 |
+
|
| 25 |
logits = model(**test).logits
|
| 26 |
predicted_ids = torch.argmax(logits, dim=-1)
|
| 27 |
labels = [model.config.id2label[_id] for _id in predicated_ids.tolist()]
|