Antoniskaraolis commited on
Commit
05e9e3a
·
1 Parent(s): 5fd43c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -18
app.py CHANGED
@@ -1,25 +1,14 @@
1
- from transformers import WhisperProcessor, WhisperForConditionalGeneration
2
  import gradio as gr
 
3
 
4
- # Load model and processor
5
- processor = WhisperProcessor.from_pretrained("openai/whisper-small")
6
- model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
 
7
 
8
- def transcribe_audio(audio_file):
9
- # Load and process the audio file
10
- audio_input, sampling_rate = processor.load_audio(audio_file.name)
11
- input_features = processor(audio_input, sampling_rate=sampling_rate, return_tensors="pt").input_features
12
-
13
- # Generate token ids and decode them to text
14
- predicted_ids = model.generate(input_features)
15
- transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
16
-
17
- return transcription[0]
18
-
19
- # Set up Gradio interface
20
  iface = gr.Interface(
21
- fn=transcribe_audio,
22
- inputs="audio",
23
  outputs="text"
24
  )
25
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small")
5
+ def transcribe(audio_file):
6
+ transcription = asr_model(audio_file)
7
+ return transcription["text"]
8
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  iface = gr.Interface(
10
+ fn=transcribe,
11
+ inputs=gr.inputs.Audio(source="microphone", type="filepath"),
12
  outputs="text"
13
  )
14