zakihassan04 commited on
Commit
fc680ae
·
verified ·
1 Parent(s): ed9ecf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
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, # haddii audio-ga dheer yahay
9
- device=-1 # CPU; haddii GPU jiro, device=0
10
  )
11
 
12
- def transcribe(audio):
13
- # audio waa path/wav array
14
- result = asr(audio, return_timestamps=False)
15
- text = result["text"]
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(source="microphone", type="filepath", label="Record Somali Input")
 
 
 
 
23
  btn = gr.Button("Transcribe")
24
- txt_out = gr.Textbox(label="Transcription")
25
- btn.click(fn=transcribe, inputs=mic, outputs=txt_out)
 
 
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()