Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,9 @@
|
|
1 |
|
2 |
-
# Import necessary modules
|
3 |
import gradio as gr
|
4 |
-
from transformers import pipeline
|
5 |
|
6 |
-
|
7 |
-
pipe = pipeline("automatic-speech-recognition", model="Futuresony/whisper-small-sw")
|
8 |
|
9 |
-
# Function to transcribe audio
|
10 |
def transcribe(audio):
|
11 |
-
|
12 |
-
return "Please upload or record an audio file."
|
13 |
-
print("Transcribing audio...")
|
14 |
-
result = pipe(audio)["text"]
|
15 |
-
return result
|
16 |
|
17 |
-
|
18 |
-
with gr.Blocks() as demo:
|
19 |
-
gr.Markdown("# ποΈ Swahili Speech-to-Text Transcription App")
|
20 |
-
|
21 |
-
with gr.Row():
|
22 |
-
audio_input = gr.Audio(source="microphone", type="filepath", label="π€ Record Audio")
|
23 |
-
file_input = gr.Audio(source="upload", type="filepath", label="π Upload Audio File")
|
24 |
-
|
25 |
-
transcribe_button = gr.Button("Transcribe")
|
26 |
-
output_text = gr.Textbox(label="π Transcription Output")
|
27 |
-
|
28 |
-
transcribe_button.click(transcribe, inputs=[audio_input], outputs=output_text)
|
29 |
-
transcribe_button.click(transcribe, inputs=[file_input], outputs=output_text)
|
30 |
-
|
31 |
-
# Launch the app
|
32 |
-
demo.launch()
|
|
|
1 |
|
|
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
whisper = gr.load("Futuresony/whisper-small-sw")
|
|
|
5 |
|
|
|
6 |
def transcribe(audio):
|
7 |
+
return whisper(audio).replace("AutomaticSpeechRecognitionOutput(text=' ", "").replace("', chunks=None)", "")
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
gr.Interface(transcribe, gr.Audio(type="filepath"), gr.Textbox()).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|