mskov commited on
Commit
62c4c95
·
1 Parent(s): ec89d20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -12,21 +12,35 @@ available_models = {
12
  "mskov/distilbert-base-toxicity" : "Distillbert Finetuned Model"
13
  }
14
 
15
- # Create a Gradio interface with a radio button to select the model
16
- def classify_toxicity(text, selected_model):
17
- # Load the selected model
18
- module = evaluate.load("toxicity", selected_model)
19
- results = module.compute(predictions=[text])
20
- toxicity_score = results["toxicity"][0]
 
 
 
 
 
 
 
 
 
 
21
  return f"Toxicity Score ({available_models[selected_model]}): {toxicity_score:.4f}"
22
 
23
  iface = gr.Interface(
24
  fn=classify_toxicity,
25
- inputs=["text", gr.Radio(available_models, type="value", label="Select Model")],
 
 
 
 
26
  outputs="text",
27
  live=True,
28
- title="Toxicity Classifier",
29
- description="Select a model and enter text to classify its toxicity.",
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)