Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
|
4 |
-
#
|
5 |
-
model_name = "
|
6 |
-
|
7 |
-
# Define the pipeline with `use_safetensors=True`
|
8 |
-
def load_pipeline():
|
9 |
-
return pipeline(
|
10 |
-
"automatic-speech-recognition",
|
11 |
-
model=model_name,
|
12 |
-
use_safetensors=True, # Ensure compatibility with safetensors
|
13 |
-
)
|
14 |
-
|
15 |
-
# Load the model pipeline
|
16 |
-
transcriber = load_pipeline()
|
17 |
|
18 |
# Define a transcription function
|
19 |
def transcribe_audio(audio_file):
|
20 |
try:
|
21 |
-
|
|
|
22 |
return transcription
|
23 |
except Exception as e:
|
24 |
return f"Error: {str(e)}"
|
@@ -29,7 +20,7 @@ interface = gr.Interface(
|
|
29 |
inputs=gr.Audio(source="upload", type="filepath", label="Upload Audio"),
|
30 |
outputs=gr.Textbox(label="Transcription"),
|
31 |
title="Sinhala Audio-to-Text Transcription",
|
32 |
-
description="Upload an audio file and get the transcription in Sinhala using the Whisper model
|
33 |
allow_flagging="never"
|
34 |
)
|
35 |
|
|
|
1 |
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)}"
|
|
|
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 |
|