Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -44,37 +44,39 @@ def classify_toxicity(audio_file, text_input, classify_anxiety):
|
|
44 |
|
45 |
else:
|
46 |
transcribed_text = text_input
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
toxicity_results = toxicity_module.compute(predictions=[transcribed_text])
|
54 |
-
|
55 |
-
toxicity_score = toxicity_results["toxicity"][0]
|
56 |
-
print(toxicity_score)
|
57 |
-
|
58 |
-
#### Text classification #####
|
59 |
-
|
60 |
-
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
61 |
-
|
62 |
-
text_classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
63 |
-
|
64 |
-
sequence_to_classify = transcribed_text
|
65 |
-
print(classify_anxiety, class_options)
|
66 |
-
candidate_labels = class_options.get(classify_anxiety, [])
|
67 |
-
# classification_output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
68 |
-
classification_output = text_classifier(sequence_to_classify, candidate_labels, multi_label=True)
|
69 |
-
print(classification_output)
|
70 |
-
|
71 |
-
#### Emotion classification ####
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
with gr.Blocks() as iface:
|
80 |
with gr.Column():
|
|
|
44 |
|
45 |
else:
|
46 |
transcribed_text = text_input
|
47 |
+
if classify_anxiety != "misophonia":
|
48 |
+
#### Toxicity Classifier ####
|
49 |
+
|
50 |
+
toxicity_module = evaluate.load("toxicity", "facebook/roberta-hate-speech-dynabench-r4-target")
|
51 |
+
#toxicity_module = evaluate.load("toxicity", 'DaNLP/da-electra-hatespeech-detection', module_type="measurement")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
toxicity_results = toxicity_module.compute(predictions=[transcribed_text])
|
54 |
+
|
55 |
+
toxicity_score = toxicity_results["toxicity"][0]
|
56 |
+
print(toxicity_score)
|
57 |
+
|
58 |
+
#### Text classification #####
|
59 |
+
|
60 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
61 |
+
|
62 |
+
text_classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
63 |
+
|
64 |
+
sequence_to_classify = transcribed_text
|
65 |
+
print(classify_anxiety, class_options)
|
66 |
+
candidate_labels = class_options.get(classify_anxiety, [])
|
67 |
+
# classification_output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
68 |
+
classification_output = text_classifier(sequence_to_classify, candidate_labels, multi_label=True)
|
69 |
+
print(classification_output)
|
70 |
+
|
71 |
+
#### Emotion classification ####
|
72 |
+
|
73 |
+
emotion_classifier = foreign_class(source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP", pymodule_file="custom_interface.py", classname="CustomEncoderWav2vec2Classifier")
|
74 |
+
out_prob, score, index, text_lab = emotion_classifier.classify_file(audio_file)
|
75 |
+
|
76 |
+
return toxicity_score, classification_output, emo_dict[text_lab[0]], transcribed_text
|
77 |
+
# return f"Toxicity Score ({available_models[selected_model]}): {toxicity_score:.4f}"
|
78 |
+
else:
|
79 |
+
return classify_anxiety
|
80 |
|
81 |
with gr.Blocks() as iface:
|
82 |
with gr.Column():
|