ortexsolution/VR1
0
1import torch2 3import gradio as gr4from transformers import pipeline5 6model_ids = {7"Fast": "openai/whisper-small",8"Balanced": "openai/whisper-medium",9"Accurate": "openai/whisper-large-v3-turbo"10}11 12device = 0 if torch.cuda.is_available() else "cpu"13 14def transcribe(inputs, model_name):15 if inputs is None:16 raise gr.Error("No audio file submitted!")17 18 pipe = pipeline(19 task="automatic-speech-recognition",20 model=model_ids[model_name],21 chunk_length_s=30,22 device=device,23 )24 text = pipe(inputs, batch_size=8, generate_kwargs={"task": "transcribe"}, return_timestamps=True)["text"] 25 return text26 27demo = gr.Blocks(theme=gr.themes.Ocean())28 29file_transcribe = gr.Interface(30 fn=transcribe,31 inputs=[32 gr.Audio(sources="upload", type="filepath", label="Audio file"),33 gr.Radio(list(model_ids.keys()), label="Select Model", value="Fast")34 ],35 outputs="text",36 title="Automated transcription of free-form voice comments",37 description=(38 "Please upload your audio file first, then select your model. Finally, click the submit button."39 ),40 flagging_mode="never",41)42mf_transcribe = gr.Interface(43 fn=transcribe,44 inputs=[45 gr.Audio(sources="microphone", type="filepath"),46 gr.Radio(list(model_ids.keys()), label="Select Model", value="Fast")47 ],48 outputs="text",49 title="Automated transcription of free-form voice comments",50 description=(51 "Please Record your audio first, then select your model. Finally, click the submit button."52 ),53 flagging_mode="never",54)55 56with demo:57 gr.TabbedInterface([file_transcribe, mf_transcribe], ["Audio File","Microphone"])58 59demo.queue().launch(ssr_mode=False)60 61 