MusIre commited on
Commit
5fcc362
Β·
1 Parent(s): e74df3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -1,7 +1,25 @@
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()