zakihassan04 commited on
Commit
b59a705
·
verified ·
1 Parent(s): 43f7fe4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -6,37 +6,35 @@ import traceback
6
  asr = pipeline(
7
  "automatic-speech-recognition",
8
  model="tacab/ASR_SOMALI",
9
- chunk_length_s=30, # split long audio into 30 s chunks if needed
10
- device=-1 # CPU; set to 0 if you enable GPU in your Space settings
11
  )
12
 
13
  def transcribe(audio_filepath):
14
  """
15
- audio_filepath: local path to the recorded WAV.
16
- Returns the transcription or an error message.
17
  """
18
  try:
19
- result = asr(audio_filepath, return_timestamps=False)
20
- return result["text"]
21
  except Exception as e:
22
- # log full stack trace to Space logs
23
  traceback.print_exc()
24
- # return a user-friendly error (you can also include str(e) if you want detail)
25
- return f"Error during transcription:\n{e}"
26
 
27
  with gr.Blocks() as demo:
28
- gr.Markdown("## Tacab Somali ASR Module")
29
  with gr.Row():
30
  mic = gr.Audio(
31
- sources=["microphone"], # allow recording from mic
32
- type="filepath", # we get a local file path
33
- label="Record Somali Input"
34
  )
35
- btn = gr.Button("Transcribe")
36
  txt_out = gr.Textbox(
37
- label="Transcription",
38
  interactive=False,
39
- placeholder="Your transcript will appear here…"
40
  )
41
 
42
  btn.click(fn=transcribe, inputs=[mic], outputs=[txt_out])
 
6
  asr = pipeline(
7
  "automatic-speech-recognition",
8
  model="tacab/ASR_SOMALI",
9
+ chunk_length_s=30, # kala jar haddii audio-ga dheer yahay
10
+ device=-1 # CPU; haddii GPU doorato, u beddel 0
11
  )
12
 
13
  def transcribe(audio_filepath):
14
  """
15
+ audio_filepath: jidka faylka WAV ee la duubay.
16
+ Soo celi qoraalka ama fariin khalad.
17
  """
18
  try:
19
+ result = asr(audio_filepath)
20
+ return result.get("text", "Qoraal lama helin.")
21
  except Exception as e:
 
22
  traceback.print_exc()
23
+ return f"Khalad inta lagu turjunayo:\n{e}"
 
24
 
25
  with gr.Blocks() as demo:
26
+ gr.Markdown("## Qalabka Tacab ASR ee Af-Soomaaliga")
27
  with gr.Row():
28
  mic = gr.Audio(
29
+ sources=["microphone"],
30
+ type="filepath",
31
+ label="Duub Cod Af-Soomaali ah"
32
  )
33
+ btn = gr.Button("Turjun")
34
  txt_out = gr.Textbox(
35
+ label="Qoraalka Turjumaadda",
36
  interactive=False,
37
+ placeholder="Halkaan ayuu qoraalkaaga ka soo muuqan doonaa…"
38
  )
39
 
40
  btn.click(fn=transcribe, inputs=[mic], outputs=[txt_out])