Spaces:
Runtime error
Runtime error
from speechbrain.pretrained.interfaces import foreign_class | |
import gradio as gr | |
import warnings | |
warnings.filterwarnings("ignore") | |
# Loading the speechbrain emotion detection model | |
learner = foreign_class( | |
source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP", | |
pymodule_file="custom_interface.py", | |
classname="CustomEncoderWav2vec2Classifier" | |
) | |
# Building prediction function for gradio | |
emotion_dict = { | |
'sad': 'Sad', | |
'hap': 'Happy', | |
'ang': 'Anger', | |
'fea': 'Fear', | |
'sur': 'Surprised', | |
'neu': 'Neutral' | |
} | |
def predict_emotion(audio): | |
out_prob, score, index, text_lab = learner.classify_file(audio.name) | |
return emotion_dict[text_lab[0]] | |
# Loading gradio interface | |
inputs = gr.inputs.Audio(label="Input Audio", type="file") | |
outputs = "text" | |
title = "ML Speech Emotion Detection" | |
description = "Speechbrain powered wav2vec 2.0 pretrained model on IEMOCAP dataset using Gradio." | |
gr.Interface(predict_emotion, inputs, outputs, title=title, description=description).launch() |