Spaces:
Runtime error
Runtime error
harish3110
commited on
Commit
•
67690fe
1
Parent(s):
32f078d
Added gradio interface
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from speechbrain.pretrained.interfaces import foreign_class
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
import warnings
|
5 |
+
warnings.filterwarnings("ignore")
|
6 |
+
|
7 |
+
# Loading the speechbrain emotion detection model
|
8 |
+
learner = foreign_class(
|
9 |
+
source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP",
|
10 |
+
# savedir="/home/harish3110/SeaWord/emotion/nbs/pretrained_models/CustomEncoderWav2vec2Classifier--8353113631630090076",
|
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 |
+
'neutral': 'Neutral'
|
21 |
+
}
|
22 |
+
|
23 |
+
def predict_emotion(audio):
|
24 |
+
out_prob, score, index, text_lab = learner.classify_file(audio.name)
|
25 |
+
return emotion_dict[text_lab[0]]
|
26 |
+
|
27 |
+
# Loading gradio interface
|
28 |
+
inputs = gr.inputs.Audio(label="Input Audio", type="file")
|
29 |
+
outputs = "text"
|
30 |
+
title = "Emotion Detection"
|
31 |
+
description = "Gradio demo for Emotion Detection. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below."
|
32 |
+
gr.Interface(predict_emotion, inputs, outputs, title=title, description=description).launch()
|