Spaces:
Sleeping
Sleeping
File size: 1,131 Bytes
88dc3ba b2593bc 527e644 b2593bc 038e82c b2593bc 038e82c b2593bc 038e82c b2593bc 527e644 b2593bc 038e82c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import subprocess
subprocess.run(["pip", "install", "datasets"])
subprocess.run(["pip", "install", "transformers"])
subprocess.run(["pip", "install", "torch", "torchvision", "torchaudio", "-f", "https://download.pytorch.org/whl/torch_stable.html"])
import gradio as gr
from transformers import WhisperProcessor, WhisperForConditionalGeneration
# 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):
# Apply custom preprocessing to the audio data if needed
processed_input = processor(audio_data, return_tensors="pt").input_features
# Generate token ids
predicted_ids = model.generate(processed_input)
# 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()
gr.Interface(fn=transcribe_audio, inputs=audio_input, outputs="text").launch()
|