|
import gradio as gr
|
|
|
|
import torch
|
|
import librosa
|
|
import json
|
|
|
|
from transformers import pipeline, AutoProcessor, AutoModelForSpeechSeq2Seq
|
|
|
|
pipe = pipeline("automatic-speech-recognition", model="dmatekenya/whisper-large-v3-chichewa")
|
|
|
|
def transcribe(audio_file_mic=None, audio_file_upload=None, language="English (eng)"):
|
|
if audio_file_mic:
|
|
audio_file = audio_file_mic
|
|
elif audio_file_upload:
|
|
audio_file = audio_file_upload
|
|
else:
|
|
return "Please upload an audio file or record one"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = pipe(audio_file)
|
|
return result["text"]
|
|
|
|
|
|
description = ''''''
|
|
|
|
iface = gr.Interface(fn=transcribe,
|
|
inputs=[
|
|
gr.Audio(source="microphone", type="filepath", label="Record Audio"),
|
|
gr.Audio(source="upload", type="filepath", label="Upload Audio"),
|
|
],
|
|
outputs=gr.Textbox(label="Transcription"),
|
|
description=description
|
|
)
|
|
iface.launch() |