Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import evaluate
|
|
| 2 |
from evaluate.utils import launch_gradio_widget
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
|
|
|
| 5 |
from transformers import AutoModelForSequenceClassification, pipeline, RobertaForSequenceClassification, RobertaTokenizer, AutoTokenizer
|
| 6 |
# pull in emotion detection
|
| 7 |
# --- Add element for specification
|
|
@@ -11,6 +12,15 @@ from transformers import AutoModelForSequenceClassification, pipeline, RobertaFo
|
|
| 11 |
# add logic to initiate mock notificaiton when detected
|
| 12 |
# pull in misophonia-specific model
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Create a Gradio interface with audio file and text inputs
|
| 15 |
def classify_toxicity(audio_file, text_input, classify_anxiety):
|
| 16 |
# Transcribe the audio file using Whisper ASR
|
|
@@ -43,8 +53,11 @@ def classify_toxicity(audio_file, text_input, classify_anxiety):
|
|
| 43 |
classification_output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
| 44 |
print(classification_output)
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
# return f"Toxicity Score ({available_models[selected_model]}): {toxicity_score:.4f}"
|
| 49 |
|
| 50 |
with gr.Blocks() as iface:
|
|
|
|
| 2 |
from evaluate.utils import launch_gradio_widget
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
| 5 |
+
from speechbrain.pretrained.interfaces import foreign_class
|
| 6 |
from transformers import AutoModelForSequenceClassification, pipeline, RobertaForSequenceClassification, RobertaTokenizer, AutoTokenizer
|
| 7 |
# pull in emotion detection
|
| 8 |
# --- Add element for specification
|
|
|
|
| 12 |
# add logic to initiate mock notificaiton when detected
|
| 13 |
# pull in misophonia-specific model
|
| 14 |
|
| 15 |
+
# Building prediction function for gradio
|
| 16 |
+
emotion_dict = {
|
| 17 |
+
'sad': 'Sad',
|
| 18 |
+
'hap': 'Happy',
|
| 19 |
+
'ang': 'Anger',
|
| 20 |
+
'neu': 'Neutral'
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
# Create a Gradio interface with audio file and text inputs
|
| 25 |
def classify_toxicity(audio_file, text_input, classify_anxiety):
|
| 26 |
# Transcribe the audio file using Whisper ASR
|
|
|
|
| 53 |
classification_output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
| 54 |
print(classification_output)
|
| 55 |
|
| 56 |
+
# Emotion classification
|
| 57 |
+
emotion_classifier = foreign_class(source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP", pymodule_file="custom_interface.py", classname="CustomEncoderWav2vec2Classifier")
|
| 58 |
+
out_prob, score, index, text_lab = learner.classify_file(audio_file.name)
|
| 59 |
+
|
| 60 |
+
return toxicity_score, classification_output, emo_dict[text_lab[0]], transcribed_text
|
| 61 |
# return f"Toxicity Score ({available_models[selected_model]}): {toxicity_score:.4f}"
|
| 62 |
|
| 63 |
with gr.Blocks() as iface:
|