Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,8 @@ def classify_toxicity(audio_file, text_input, classify_anxiety):
|
|
| 33 |
else:
|
| 34 |
transcribed_text = text_input
|
| 35 |
|
| 36 |
-
|
|
|
|
| 37 |
toxicity_module = evaluate.load("toxicity", "facebook/roberta-hate-speech-dynabench-r4-target")
|
| 38 |
#toxicity_module = evaluate.load("toxicity", 'DaNLP/da-electra-hatespeech-detection', module_type="measurement")
|
| 39 |
|
|
@@ -42,18 +43,20 @@ def classify_toxicity(audio_file, text_input, classify_anxiety):
|
|
| 42 |
toxicity_score = toxicity_results["toxicity"][0]
|
| 43 |
print(toxicity_score)
|
| 44 |
|
| 45 |
-
|
| 46 |
|
| 47 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
sequence_to_classify = transcribed_text
|
| 52 |
candidate_labels = classify_anxiety
|
| 53 |
-
classification_output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
|
|
|
| 54 |
print(classification_output)
|
| 55 |
|
| 56 |
-
|
|
|
|
| 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 |
|
|
|
|
| 33 |
else:
|
| 34 |
transcribed_text = text_input
|
| 35 |
|
| 36 |
+
#### Toxicity Classifier ####
|
| 37 |
+
|
| 38 |
toxicity_module = evaluate.load("toxicity", "facebook/roberta-hate-speech-dynabench-r4-target")
|
| 39 |
#toxicity_module = evaluate.load("toxicity", 'DaNLP/da-electra-hatespeech-detection', module_type="measurement")
|
| 40 |
|
|
|
|
| 43 |
toxicity_score = toxicity_results["toxicity"][0]
|
| 44 |
print(toxicity_score)
|
| 45 |
|
| 46 |
+
#### Text classification #####
|
| 47 |
|
| 48 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 49 |
|
| 50 |
+
text_classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli")
|
| 51 |
|
| 52 |
sequence_to_classify = transcribed_text
|
| 53 |
candidate_labels = classify_anxiety
|
| 54 |
+
# classification_output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
| 55 |
+
classification_output = text_classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
| 56 |
print(classification_output)
|
| 57 |
|
| 58 |
+
#### Emotion classification ####
|
| 59 |
+
|
| 60 |
emotion_classifier = foreign_class(source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP", pymodule_file="custom_interface.py", classname="CustomEncoderWav2vec2Classifier")
|
| 61 |
out_prob, score, index, text_lab = learner.classify_file(audio_file.name)
|
| 62 |
|