Spaces:
Runtime error
Runtime error
abdulelahagr
commited on
Commit
•
5919642
1
Parent(s):
4814d7e
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load the Whisper model
|
5 |
+
whisper_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
6 |
+
# Load the fine-tuned BERT model for harassment classification
|
7 |
+
bert_pipe = pipeline("text-classification", model="abdulelahagr/harassment_lang_classifier")
|
8 |
+
|
9 |
+
def classify_harassment(text):
|
10 |
+
predicted_category = bert_pipe(text)
|
11 |
+
return predicted_category
|
12 |
+
|
13 |
+
|
14 |
+
def process_audio(speech_file):
|
15 |
+
whisper_result = whisper_pipe(speech_file, generate_kwargs={"language": "english"})
|
16 |
+
transcription = whisper_result["text"]
|
17 |
+
|
18 |
+
# 2. Classify the transcribed text
|
19 |
+
classification_result = classify_harassment(transcription)
|
20 |
+
predicted_label = classification_result[0]['label']
|
21 |
+
print(transcription, predicted_label)
|
22 |
+
# 3. Prepare results for display
|
23 |
+
return transcription, predicted_label
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("## Kids harassment Classification")
|
29 |
+
audio_input = gr.Audio(type="filepath")
|
30 |
+
btn_process = gr.Button("Process")
|
31 |
+
transcription_output = gr.Textbox(label="Transcription")
|
32 |
+
classification_output = gr.Label(label="Classification Result")
|
33 |
+
|
34 |
+
btn_process.click(process_audio, inputs=audio_input, outputs=[transcription_output, classification_output])
|
35 |
+
|
36 |
+
demo.launch(debug=True)
|