Spaces:
Sleeping
Sleeping
File size: 1,338 Bytes
ed9ecf7 43f7fe4 ed9ecf7 b59a705 ed9ecf7 fc680ae 43f7fe4 b59a705 5b99996 43f7fe4 5b99996 43f7fe4 b59a705 43f7fe4 b59a705 ed9ecf7 b59a705 ed9ecf7 fc680ae b59a705 fc680ae b59a705 43f7fe4 b59a705 43f7fe4 b59a705 43f7fe4 fc680ae ed9ecf7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import gradio as gr
from transformers import pipeline
import traceback
# 1) Load ASR pipeline
asr = pipeline(
"automatic-speech-recognition",
model="tacab/ASR_SOMALI",
chunk_length_s=30, # kala jar haddii audio-ga dheer yahay
device=-1 # CPU; haddii GPU doorato, u beddel 0
)
def transcribe(audio_filepath):
"""
audio_filepath: jidka faylka WAV ee la duubay.
Haddii user-ku duubin waayo, soo celi fariin.
"""
if not audio_filepath:
return "Fadlan marka hore duub cod, ka dibna riix ‘Turjun’."
try:
result = asr(audio_filepath)
return result.get("text", "Qoraal lama helin.")
except Exception as e:
traceback.print_exc()
return f"Khalad inta lagu turjunayo:\n{e}"
with gr.Blocks() as demo:
gr.Markdown("## Qalabka Tacab ASR ee Af-Soomaaliga")
with gr.Row():
mic = gr.Audio(
sources=["microphone"],
type="filepath",
label="Duub Cod Af-Soomaali ah"
)
btn = gr.Button("Turjun")
txt_out = gr.Textbox(
label="Qoraalka Turjumaadda",
interactive=False,
placeholder="Halkaan ayuu qoraalkaaga ka soo muuqan doonaa…"
)
btn.click(fn=transcribe, inputs=[mic], outputs=[txt_out])
if __name__ == "__main__":
demo.launch()
|