Spaces:
Runtime error
Runtime error
seikin_alexey
commited on
Commit
·
b2f62bf
1
Parent(s):
2355a75
app3.py
CHANGED
|
@@ -4,7 +4,35 @@ import os
|
|
| 4 |
import warnings
|
| 5 |
warnings.filterwarnings("ignore")
|
| 6 |
|
| 7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Get the list of audio files for the dropdown
|
| 10 |
audio_files_list = get_audio_files_list()
|
|
|
|
| 4 |
import warnings
|
| 5 |
warnings.filterwarnings("ignore")
|
| 6 |
|
| 7 |
+
# Function to get the list of audio files in the 'rec/' directory
|
| 8 |
+
def get_audio_files_list(directory="rec"):
|
| 9 |
+
try:
|
| 10 |
+
return [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
|
| 11 |
+
except FileNotFoundError:
|
| 12 |
+
print("The 'rec' directory does not exist. Please make sure it is the correct path.")
|
| 13 |
+
return []
|
| 14 |
+
|
| 15 |
+
# Loading the speechbrain emotion detection model
|
| 16 |
+
learner = foreign_class(
|
| 17 |
+
source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP",
|
| 18 |
+
pymodule_file="custom_interface.py",
|
| 19 |
+
classname="CustomEncoderWav2vec2Classifier"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Building prediction function for Gradio
|
| 23 |
+
emotion_dict = {
|
| 24 |
+
'sad': 'Sad',
|
| 25 |
+
'hap': 'Happy',
|
| 26 |
+
'ang': 'Anger',
|
| 27 |
+
'fea': 'Fear',
|
| 28 |
+
'sur': 'Surprised',
|
| 29 |
+
'neu': 'Neutral'
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
def predict_emotion(selected_audio):
|
| 33 |
+
file_path = os.path.join("rec", selected_audio)
|
| 34 |
+
out_prob, score, index, text_lab = learner.classify_file(file_path)
|
| 35 |
+
return emotion_dict[text_lab[0]]
|
| 36 |
|
| 37 |
# Get the list of audio files for the dropdown
|
| 38 |
audio_files_list = get_audio_files_list()
|