File size: 1,302 Bytes
5919642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from transformers import pipeline
import gradio as gr

# Load the Whisper model
whisper_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-small")
# Load the fine-tuned BERT model for harassment classification
bert_pipe = pipeline("text-classification", model="abdulelahagr/harassment_lang_classifier")

def classify_harassment(text):
    predicted_category = bert_pipe(text)
    return predicted_category


def process_audio(speech_file):
    whisper_result = whisper_pipe(speech_file, generate_kwargs={"language": "english"})
    transcription = whisper_result["text"]

    # 2. Classify the transcribed text
    classification_result = classify_harassment(transcription)
    predicted_label = classification_result[0]['label']
    print(transcription, predicted_label)
    # 3. Prepare results for display
    return transcription, predicted_label



with gr.Blocks() as demo:
    gr.Markdown("## Kids harassment Classification")
    audio_input = gr.Audio(type="filepath")
    btn_process = gr.Button("Process")
    transcription_output = gr.Textbox(label="Transcription")
    classification_output = gr.Label(label="Classification Result")

    btn_process.click(process_audio, inputs=audio_input, outputs=[transcription_output, classification_output])

demo.launch(debug=True)