Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,21 +12,35 @@ available_models = {
|
|
12 |
"mskov/distilbert-base-toxicity" : "Distillbert Finetuned Model"
|
13 |
}
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
return f"Toxicity Score ({available_models[selected_model]}): {toxicity_score:.4f}"
|
22 |
|
23 |
iface = gr.Interface(
|
24 |
fn=classify_toxicity,
|
25 |
-
inputs=[
|
|
|
|
|
|
|
|
|
26 |
outputs="text",
|
27 |
live=True,
|
28 |
-
title="Toxicity Classifier",
|
29 |
-
description="
|
30 |
)
|
31 |
|
32 |
launch_gradio_widget(iface)
|
|
|
12 |
"mskov/distilbert-base-toxicity" : "Distillbert Finetuned Model"
|
13 |
}
|
14 |
|
15 |
+
|
16 |
+
# Create a Gradio interface with audio file and text inputs
|
17 |
+
def classify_toxicity(audio_file, text_input, selected_model):
|
18 |
+
# Transcribe the audio file using Whisper ASR
|
19 |
+
whisper_module = evaluate.load("whisper")
|
20 |
+
transcription_results = whisper_module.compute(uploaded=audio_file)
|
21 |
+
|
22 |
+
# Extract the transcribed text
|
23 |
+
transcribed_text = transcription_results["transcription"]
|
24 |
+
|
25 |
+
# Load the selected toxicity classification model
|
26 |
+
toxicity_module = evaluate.load("toxicity", selected_model)
|
27 |
+
toxicity_results = toxicity_module.compute(predictions=[transcribed_text])
|
28 |
+
|
29 |
+
toxicity_score = toxicity_results["toxicity"][0]
|
30 |
+
|
31 |
return f"Toxicity Score ({available_models[selected_model]}): {toxicity_score:.4f}"
|
32 |
|
33 |
iface = gr.Interface(
|
34 |
fn=classify_toxicity,
|
35 |
+
inputs=[
|
36 |
+
gr.Audio(source="upload", type="file", label="Upload Audio File (Optional)"),
|
37 |
+
"text",
|
38 |
+
gr.Radio(available_models, type="value", label="Select Model")
|
39 |
+
],
|
40 |
outputs="text",
|
41 |
live=True,
|
42 |
+
title="Toxicity Classifier with ASR",
|
43 |
+
description="Upload an audio file or enter text to classify its toxicity using the selected model.",
|
44 |
)
|
45 |
|
46 |
launch_gradio_widget(iface)
|