MetiMiester commited on
Commit
176ca41
·
verified ·
1 Parent(s): c6ce371

git add requirements.txt git commit -m "Install openai-whisper instead of whisper" git push

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -7,24 +7,18 @@ import gradio as gr
7
  # 1) Load your balanced text classifier
8
  text_clf = joblib.load("text_pipeline_balanced.joblib")
9
 
10
- # 2) Load Whisper-Large-v2 via openai/whisper on CPU
11
- model = whisper.load_model("large-v2") # Change to "base" if you want smaller
12
 
13
  def classify(audio_path):
14
  """
15
  audio_path: str → path to the uploaded file
16
  returns: transcript (str), safety probabilities (dict), unsafe probability (str)
17
  """
18
- # Read & convert to mono 16k WAV
19
- audio, sr = sf.read(audio_path, dtype="float32")
20
- if audio.ndim > 1:
21
- audio = audio.mean(axis=1)
22
- # Whisper’s .transcribe will resample internally if needed
23
-
24
  # Run beam search transcription
25
  result = model.transcribe(
26
  audio_path,
27
- beam_size=5, # beam search for quality
28
  language="en"
29
  )
30
  txt = result["text"].strip()
@@ -47,7 +41,7 @@ iface = gr.Interface(
47
  inputs=audio_input,
48
  outputs=[transcript_out, probs_out, unsafe_out],
49
  title="BubbleGuard Audio Safety Checker",
50
- description="Uses the official whisper package for identical, CPU-only transcripts."
51
  )
52
 
53
  if __name__ == "__main__":
 
7
  # 1) Load your balanced text classifier
8
  text_clf = joblib.load("text_pipeline_balanced.joblib")
9
 
10
+ # 2) Load Whisper-Large-v2 via official OpenAI Whisper on CPU
11
+ model = whisper.load_model("large-v2") # or "base" for a smaller model
12
 
13
  def classify(audio_path):
14
  """
15
  audio_path: str → path to the uploaded file
16
  returns: transcript (str), safety probabilities (dict), unsafe probability (str)
17
  """
 
 
 
 
 
 
18
  # Run beam search transcription
19
  result = model.transcribe(
20
  audio_path,
21
+ beam_size=5, # beam search for higher accuracy
22
  language="en"
23
  )
24
  txt = result["text"].strip()
 
41
  inputs=audio_input,
42
  outputs=[transcript_out, probs_out, unsafe_out],
43
  title="BubbleGuard Audio Safety Checker",
44
+ description="Uses the official openai-whisper package for identical, CPU-only transcripts."
45
  )
46
 
47
  if __name__ == "__main__":