import torchaudio import streamlit as st from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq # Load the ASR model and processor processor = AutoProcessor.from_pretrained("mohammed/whisper-large-arabic-cv-11") model = AutoModelForSpeechSeq2Seq.from_pretrained("mohammed/whisper-large-arabic-cv-11") audio_file = st.file_uploader("Upload Audio", type=["wav", "mp3", "m4a"]) st.title("Arabic ASR model") if st.sidebar.button("Transcribe Audio"): if audio_file is not None: st.sidebar.success("Transcribing Audio >>>>") # Load the audio file audio_tensor, sample_rate = torchaudio.load(audio_file) # Resample if necessary if sample_rate != 16000: resampler = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000) audio_tensor = resampler(audio_tensor) # Convert the audio tensor to a numpy array audio_np = audio_tensor.squeeze().numpy() # Process the audio inputs = processor(audio_np, sampling_rate=16000, return_tensors="pt") # Generate transcription generated_ids = model.generate(inputs["input_features"]) transcription = processor.batch_decode(generated_ids, skip_special_tokens=True) # Display transcription st.sidebar.success("Transcription Complete!") st.text(transcription[0]) else: st.sidebar.error("Please upload a valid audio file")