Spaces:
Sleeping
Sleeping
# Load model directly | |
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq | |
import torchaudio | |
import streamlit as st | |
processor = AutoProcessor.from_pretrained("mohammed/whisper-small-arabic-cv-11") | |
model = AutoModelForSpeechSeq2Seq.from_pretrained("mohammed/whisper-small-arabic-cv-11") | |
st.title("Arabic Whisper model v2") | |
audio_file = st.file_uploader("Upload audio", type=["mp3", "wav", "m4a"]) | |
if st.sidebar.button("Trascribe Audio"): | |
if audio_file is not None: | |
st.sidebar.success("Transcribing audio") # on success audio file | |
audio_tensor, sample_rate = torchaudio.load(audio_file) | |
if sample_rate != 16000: | |
resampler = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000) | |
audio_tensor = resampler(audio_tensor) | |
audio_np = audio_tensor.squeeze().numpy() | |
# processing audio | |
inputs = processor(audio_np, sample_rate=16000, return_tensors="pt") | |
# generating transcript | |
generated_ids = model.generate(inputs["input_features"]) | |
transcription = processor.batch_decode(generated_ids, skip_special_tokens=True) | |
# display transcription | |
st.sidebar.success("Transcription is complete") | |
st.text(transcription[0]) | |
else: | |
st.sidebar.error("Please upload a valid audio file") |