test / app.py
MusIre's picture
Update app.py
1aea5eb
raw
history blame
973 Bytes
pip install datasets
pip install transformers
from transformers import WhisperProcessor, WhisperForConditionalGeneration
from datasets import load_dataset
import gradio as gr
# Load model and processor
processor = WhisperProcessor.from_pretrained("openai/whisper-large")
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")
model.config.forced_decoder_ids = None
# Function to perform ASR on audio data
def transcribe_audio(audio_data):
# Process audio data using the Whisper processor
input_features = processor(audio_data, return_tensors="pt").input_features
# Generate token ids
predicted_ids = model.generate(input_features)
# Decode token ids to text
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
return transcription[0]
# Create Gradio interface
audio_input = gr.Audio(preprocessing_fn=None)
gr.Interface(fn=transcribe_audio, inputs=audio_input, outputs="text").launch()