Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,43 @@
|
|
1 |
import evaluate
|
2 |
from evaluate.utils import launch_gradio_widget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
launch_gradio_widget(module)
|
|
|
1 |
import evaluate
|
2 |
from evaluate.utils import launch_gradio_widget
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import AutoModelForSequenceClassification, pipeline, RobertaForSequenceClassification, RobertaTokenizer, AutoTokenizer
|
5 |
+
|
6 |
+
|
7 |
+
# Define the list of available models
|
8 |
+
available_models = {
|
9 |
+
"mskov/roberta-base-toxicity": "Roberta Finetuned Model"
|
10 |
+
}
|
11 |
+
|
12 |
+
|
13 |
+
# Create a Gradio interface with audio file and text inputs
|
14 |
+
def classify_toxicity(audio_file, text_input, selected_model):
|
15 |
+
# Transcribe the audio file using Whisper ASR
|
16 |
+
whisper_module = evaluate.load("whisper")
|
17 |
+
transcription_results = whisper_module.compute(uploaded=audio_file)
|
18 |
+
|
19 |
+
# Extract the transcribed text
|
20 |
+
transcribed_text = transcription_results["transcription"]
|
21 |
+
|
22 |
+
# Load the selected toxicity classification model
|
23 |
+
toxicity_module = evaluate.load("toxicity", selected_model)
|
24 |
+
toxicity_results = toxicity_module.compute(predictions=[transcribed_text])
|
25 |
+
|
26 |
+
toxicity_score = toxicity_results["toxicity"][0]
|
27 |
+
|
28 |
+
return f"Toxicity Score ({available_models[selected_model]}): {toxicity_score:.4f}"
|
29 |
+
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=classify_toxicity,
|
32 |
+
inputs=[
|
33 |
+
gr.Audio(source="upload", type="file", label="Upload Audio File (Optional)"),
|
34 |
+
"text",
|
35 |
+
gr.Radio(available_models, type="value", label="Select Model")
|
36 |
+
],
|
37 |
+
outputs="text",
|
38 |
+
live=True,
|
39 |
+
title="Toxicity Classifier with ASR",
|
40 |
+
description="Upload an audio file or enter text to classify its toxicity using the selected model.",
|
41 |
+
)
|
42 |
|
43 |
+
iface.launch()
|
|