Athspi commited on
Commit
8a6a9a9
·
verified ·
1 Parent(s): 46e752c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -1,10 +1,10 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
- from pydub import AudioSegment
4
  import os
 
5
 
6
- # Load a smaller Whisper model for faster transcription
7
- model = pipeline("automatic-speech-recognition", model="openai/whisper-base")
8
 
9
  def split_audio(filepath, chunk_length_ms=30000):
10
  """Split audio into chunks of `chunk_length_ms` milliseconds."""
@@ -26,12 +26,12 @@ def transcribe_audio(audio_file):
26
  detected_language = None
27
 
28
  for chunk in chunks:
29
- # Enable language detection and transcription
30
- result = model(chunk, generate_kwargs={"task": "transcribe", "language": None}) # Let Whisper detect language
31
  transcriptions.append(result["text"])
32
 
33
- # Extract detected language from the result (if available)
34
- if "language" in result:
35
  detected_language = result["language"]
36
 
37
  os.remove(chunk) # Clean up chunk files
 
1
  import gradio as gr
2
+ import whisper
 
3
  import os
4
+ from pydub import AudioSegment
5
 
6
+ # Load the Whisper model
7
+ model = whisper.load_model("base") # Use "base" for faster processing
8
 
9
  def split_audio(filepath, chunk_length_ms=30000):
10
  """Split audio into chunks of `chunk_length_ms` milliseconds."""
 
26
  detected_language = None
27
 
28
  for chunk in chunks:
29
+ # Transcribe the chunk and detect the language
30
+ result = model.transcribe(chunk, fp16=False) # Set fp16=False if not using GPU
31
  transcriptions.append(result["text"])
32
 
33
+ # Extract detected language from the result
34
+ if detected_language is None and "language" in result:
35
  detected_language = result["language"]
36
 
37
  os.remove(chunk) # Clean up chunk files