MetiMiester commited on
Commit
6ab6751
·
verified ·
1 Parent(s): 427cfe5

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +41 -0
  2. requirements.txt +7 -0
  3. text_pipeline_balanced.joblib +3 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import torch
4
+ import soundfile as sf
5
+ import numpy as np
6
+ from transformers import pipeline
7
+
8
+ # 1) Load your trained text classifier
9
+ text_clf = joblib.load("text_pipeline_balanced.joblib")
10
+
11
+ # 2) Initialize Whisper ASR
12
+ device = 0 if torch.cuda.is_available() else -1
13
+ asr = pipeline(
14
+ "automatic-speech-recognition",
15
+ model="openai/whisper-base",
16
+ chunk_length_s=30,
17
+ device=device,
18
+ ignore_warning=True,
19
+ generate_kwargs={"language":"en","task":"transcribe"}
20
+ )
21
+
22
+ def classify_audio_file(filepath):
23
+ audio, sr = sf.read(filepath, dtype="float32")
24
+ if audio.ndim>1: audio = audio.mean(axis=1)
25
+ transcript = asr({"array": audio, "sampling_rate": sr})["text"].strip()
26
+ proba = text_clf.predict_proba([transcript])[0][1]
27
+ label = "❌ Unsafe" if proba>0.5 else "✅ Safe"
28
+ return transcript, label, float(proba)
29
+
30
+ demo = gr.Interface(
31
+ fn=classify_audio_file,
32
+ inputs=gr.Audio(source="microphone", type="filepath", label="Record or upload audio"),
33
+ outputs=[gr.Textbox(label="Transcript"),
34
+ gr.Label(num_top_classes=2, label="Safety Label"),
35
+ gr.Number(label="Unsafe Probability")],
36
+ title="BubbleGuard Audio Safety",
37
+ description="Transcribe & flag voice-notes as safe/unsafe"
38
+ )
39
+
40
+ if __name__=="__main__":
41
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch
4
+ soundfile
5
+ joblib
6
+ scikit-learn
7
+ numpy
text_pipeline_balanced.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:60bdf7fdefcf512141d90f004907780233c3a110b0909b55e1fc59f6963b85b6
3
+ size 461844