import spaces import torch import gradio as gr from transformers import pipeline from transformers.pipelines.audio_utils import ffmpeg_read import tempfile import os MODEL_NAME = "alakxender/whisper-large-dv-a40" BATCH_SIZE = 8 FILE_LIMIT_MB = 1000 device = 0 if torch.cuda.is_available() else "cpu" pipe = pipeline( task="automatic-speech-recognition", model=MODEL_NAME, chunk_length_s=30, device=device, ) @spaces.GPU def transcribe(inputs): if inputs is None: raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.") text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": "transcribe"}, return_timestamps=True)["text"] return text # Custom CSS with modern Gradio styling custom_css = """ .thaana-textbox textarea { font-size: 18px !important; font-family: 'MV_Faseyha', 'Faruma', 'A_Faruma', 'Noto Sans Thaana', 'MV Boli' !important; line-height: 1.8 !important; direction: rtl !important; } """ demo = gr.Blocks(css=custom_css) file_transcribe = gr.Interface( fn=transcribe, inputs=[ gr.Audio(type="filepath", label="Audio file"), ], outputs= gr.Textbox( label="", lines=2, elem_classes=["thaana-textbox"], rtl=True ), title="Whisper Large V3: Transcribe Audio", description=( "" ), allow_flagging="never", ) with demo: gr.TabbedInterface([file_transcribe], ["Audio file"]) demo.queue().launch()