Athspi commited on
Commit
d30da85
·
verified ·
1 Parent(s): 96ba16a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -2,26 +2,33 @@ import gradio as gr
2
  from faster_whisper import WhisperModel
3
 
4
  # Load the Faster Whisper model
5
- model_name = "Systran/faster-whisper-large-v3"
6
- model = WhisperModel(model_name, device="cpu") # Use "cuda" if you have a GPU
7
 
8
- # Define a transcription function
9
  def transcribe_audio(audio_file):
 
 
 
10
  try:
11
- segments, info = model.transcribe(audio_file, beam_size=5) # Customize parameters as needed
12
- transcription = " ".join([segment.text for segment in segments])
 
 
13
  return transcription
14
  except Exception as e:
15
  return f"Error: {str(e)}"
16
 
17
- # Create Gradio interface
18
  interface = gr.Interface(
19
- fn=transcribe_audio,
20
- inputs=gr.Audio(source="upload", type="filepath", label="Upload Audio"),
21
- outputs=gr.Textbox(label="Transcription"),
22
- title="Sinhala Audio-to-Text Transcription",
23
- description="Upload an audio file and get the transcription in Sinhala using the Faster Whisper model.",
24
- allow_flagging="never"
 
 
 
25
  )
26
 
27
  # Launch the Gradio app
 
2
  from faster_whisper import WhisperModel
3
 
4
  # Load the Faster Whisper model
5
+ model = WhisperModel("large-v3", device="cpu") # Use "cuda" for GPU
 
6
 
7
+ # Define the transcription function
8
  def transcribe_audio(audio_file):
9
+ """
10
+ Transcribes the audio file using the Faster Whisper model.
11
+ """
12
  try:
13
+ segments, info = model.transcribe(audio_file, beam_size=5) # Adjust beam_size as needed
14
+ transcription = "\n".join(
15
+ [f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}" for segment in segments]
16
+ )
17
  return transcription
18
  except Exception as e:
19
  return f"Error: {str(e)}"
20
 
21
+ # Create the Gradio interface
22
  interface = gr.Interface(
23
+ fn=transcribe_audio, # Function to process the input
24
+ inputs=gr.Audio(source="upload", type="filepath", label="Upload Audio"), # Input: Audio file
25
+ outputs=gr.Textbox(label="Transcription"), # Output: Textbox for the transcription
26
+ title="Audio-to-Text Transcription",
27
+ description=(
28
+ "Upload an audio file and get the transcription using the Faster Whisper model "
29
+ "large-v3. Supports high-quality transcription with beam search."
30
+ ),
31
+ allow_flagging="never",
32
  )
33
 
34
  # Launch the Gradio app