lyimo commited on
Commit
7fe2d10
·
verified ·
1 Parent(s): 65249b7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the ASR pipeline
5
+ pipe = pipeline(
6
+ "automatic-speech-recognition",
7
+ model="lyimo/whisper-small-sw-badili-v4"
8
+ )
9
+
10
+ def transcribe(audio):
11
+ if audio is None:
12
+ return ""
13
+
14
+ # Process audio file path with pipeline
15
+ result = pipe(
16
+ audio,
17
+ generate_kwargs={"language": "swahili"}
18
+ )
19
+ return result["text"]
20
+
21
+ # Create Gradio interface
22
+ interface = gr.Interface(
23
+ fn=transcribe,
24
+ inputs=gr.Audio(sources=["microphone", "upload"], type="filepath"),
25
+ outputs=gr.Textbox(label="Transcription"),
26
+ title="Swahili Speech Recognition",
27
+ description="Record or upload Swahili audio to see the Whisper transcription",
28
+ allow_flagging="never"
29
+ )
30
+
31
+ # Launch the app
32
+ interface.launch()