Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,24 +5,28 @@ from transformers import pipeline
|
|
5 |
asr = pipeline(
|
6 |
"automatic-speech-recognition",
|
7 |
model="tacab/ASR_SOMALI",
|
8 |
-
chunk_length_s=30,
|
9 |
-
device=-1
|
10 |
)
|
11 |
|
12 |
-
def transcribe(
|
13 |
-
|
14 |
-
result = asr(
|
15 |
-
|
16 |
-
return text
|
17 |
|
18 |
-
# 2) Gradio Interface
|
19 |
with gr.Blocks() as demo:
|
20 |
gr.Markdown("## Tacab Somali ASR Module")
|
21 |
with gr.Row():
|
22 |
-
mic = gr.Audio(
|
|
|
|
|
|
|
|
|
23 |
btn = gr.Button("Transcribe")
|
24 |
-
txt_out = gr.Textbox(label="Transcription")
|
25 |
-
|
|
|
|
|
26 |
|
27 |
if __name__ == "__main__":
|
28 |
demo.launch()
|
|
|
5 |
asr = pipeline(
|
6 |
"automatic-speech-recognition",
|
7 |
model="tacab/ASR_SOMALI",
|
8 |
+
chunk_length_s=30, # split long audio into 30 s chunks
|
9 |
+
device=-1 # use CPU; set to 0 if you enable GPU in your Space
|
10 |
)
|
11 |
|
12 |
+
def transcribe(audio_filepath):
|
13 |
+
"""Run the ASR model on the given WAV file path and return the text."""
|
14 |
+
result = asr(audio_filepath, return_timestamps=False)
|
15 |
+
return result["text"]
|
|
|
16 |
|
|
|
17 |
with gr.Blocks() as demo:
|
18 |
gr.Markdown("## Tacab Somali ASR Module")
|
19 |
with gr.Row():
|
20 |
+
mic = gr.Audio(
|
21 |
+
sources=["microphone"], # allow recording from mic
|
22 |
+
type="filepath", # give us a local file path
|
23 |
+
label="Record Somali Input"
|
24 |
+
)
|
25 |
btn = gr.Button("Transcribe")
|
26 |
+
txt_out = gr.Textbox(label="Transcription", interactive=False)
|
27 |
+
|
28 |
+
# wire up the button: take mic as input, produce txt_out
|
29 |
+
btn.click(fn=transcribe, inputs=[mic], outputs=[txt_out])
|
30 |
|
31 |
if __name__ == "__main__":
|
32 |
demo.launch()
|