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()