Spaces:
Runtime error
Runtime error
Commit
·
e893152
1
Parent(s):
a14fce4
Delete app2.py
Browse files
app2.py
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from speechbrain.pretrained.interfaces import foreign_class
|
| 3 |
-
import gradio as gr
|
| 4 |
-
|
| 5 |
-
import warnings
|
| 6 |
-
warnings.filterwarnings("ignore")
|
| 7 |
-
|
| 8 |
-
# Loading the speechbrain emotion detection model
|
| 9 |
-
learner = foreign_class(
|
| 10 |
-
source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP",
|
| 11 |
-
pymodule_file="custom_interface.py",
|
| 12 |
-
classname="CustomEncoderWav2vec2Classifier"
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
# Building prediction function for gradio
|
| 16 |
-
emotion_dict = {
|
| 17 |
-
'sad': 'Sad',
|
| 18 |
-
'hap': 'Happy',
|
| 19 |
-
'ang': 'Anger',
|
| 20 |
-
'fea': 'Fear',
|
| 21 |
-
'sur': 'Surprised',
|
| 22 |
-
'neu': 'Neutral'
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
def predict_emotion(file_path):
|
| 26 |
-
# Since we get the file path from the dropdown, we don't need to access the `.name` property
|
| 27 |
-
out_prob, score, index, text_lab = learner.classify_file(file_path)
|
| 28 |
-
return emotion_dict[text_lab[0]]
|
| 29 |
-
|
| 30 |
-
# Folder containing audio files
|
| 31 |
-
folder = "prerecorded"
|
| 32 |
-
|
| 33 |
-
# Assuming that the 'prerecorded' folder is in the current working directory
|
| 34 |
-
# Change the working directory path if necessary
|
| 35 |
-
audio_files = [os.path.join(folder, file) for file in os.listdir(folder) if file.endswith('.wav')]
|
| 36 |
-
|
| 37 |
-
# Loading gradio interface with dropdown for audio selection
|
| 38 |
-
inputs = gr.inputs.Dropdown(audio_files, label="Select Audio File")
|
| 39 |
-
outputs = "text"
|
| 40 |
-
title = "Machine Learning Emotion Detection"
|
| 41 |
-
description = "Gradio demo for Emotion Detection. To use it, select an audio file from the dropdown and click 'Submit'. Read more at the links below."
|
| 42 |
-
gr.Interface(predict_emotion, inputs, outputs, title=title, description=description).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|