Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,25 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
2 |
+
from datasets import load_dataset
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# Load model and processor
|
6 |
+
processor = WhisperProcessor.from_pretrained("openai/whisper-large")
|
7 |
+
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")
|
8 |
+
model.config.forced_decoder_ids = None
|
9 |
|
10 |
+
# Function to perform ASR on audio data
|
11 |
+
def transcribe_audio(audio_data):
|
12 |
+
# Process audio data using the Whisper processor
|
13 |
+
input_features = processor(audio_data, return_tensors="pt").input_features
|
14 |
+
|
15 |
+
# Generate token ids
|
16 |
+
predicted_ids = model.generate(input_features)
|
17 |
+
|
18 |
+
# Decode token ids to text
|
19 |
+
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
20 |
+
|
21 |
+
return transcription[0]
|
22 |
+
|
23 |
+
# Create Gradio interface
|
24 |
+
audio_input = gr.Audio(preprocessing_fn=None)
|
25 |
+
gr.Interface(fn=transcribe_audio, inputs=audio_input, outputs="text").launch()
|