Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,44 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
# 1) Load ASR pipeline
|
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 #
|
10 |
)
|
11 |
|
12 |
def transcribe(audio_filepath):
|
13 |
-
"""
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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", #
|
23 |
label="Record Somali Input"
|
24 |
)
|
25 |
btn = gr.Button("Transcribe")
|
26 |
-
txt_out = gr.Textbox(
|
|
|
|
|
|
|
|
|
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__":
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import traceback
|
4 |
|
5 |
# 1) Load ASR pipeline
|
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])
|
43 |
|
44 |
if __name__ == "__main__":
|