dl_final / app.py
233-Yorozuya's picture
Rename asr.py to app.py
9b9c28e verified
raw
history blame
1.16 kB
import streamlit as st
from transformers import WhisperProcessor, WhisperForConditionalGeneration
import torchaudio
# Load the model
@st.cache_resource
def load_model():
processor = WhisperProcessor.from_pretrained("233-Yorozuya/dl_whisper_model")
model = WhisperForConditionalGeneration.from_pretrained("233-Yorozuya/dl_whisper_model")
return processor, model
processor, model = load_model()
st.title("ASR with Fine-Tuned Whisper")
st.write("Upload an audio file for transcription:")
# File upload
audio_file = st.file_uploader("Choose an audio file", type=["wav", "mp3", "ogg"])
if audio_file:
# Load and preprocess audio
audio, rate = torchaudio.load(audio_file)
audio = torchaudio.transforms.Resample(orig_freq=rate, new_freq=16000)(audio)
inputs = processor(audio[0].numpy(), sampling_rate=16000, return_tensors="pt")
# Perform inference
with st.spinner("Transcribing..."):
predicted_ids = model.generate(inputs.input_features)
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
# Display result
st.subheader("Transcription")
st.write(transcription)