Sharfraz commited on
Commit
5625178
·
verified ·
1 Parent(s): 3acc936

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -1
app.py CHANGED
@@ -1 +1,29 @@
1
- app.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import WhisperProcessor, FlaxWhisperForConditionalGeneration
3
+
4
+ # Load Whisper model
5
+ model_name = "openai/whisper-large"
6
+ processor = WhisperProcessor.from_pretrained(model_name)
7
+ model = FlaxWhisperForConditionalGeneration.from_pretrained(model_name)
8
+
9
+ def transcribe(audio):
10
+ # Preprocess audio
11
+ inputs = processor(audio, return_tensors="np", sampling_rate=16000)
12
+ input_features = inputs.input_features
13
+
14
+ # Generate transcription
15
+ predicted_ids = model.generate(input_features)
16
+ transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
17
+
18
+ return transcription
19
+
20
+ # Gradio Interface
21
+ interface = gr.Interface(
22
+ fn=transcribe,
23
+ inputs=gr.Audio(source="upload", type="numpy"),
24
+ outputs="text",
25
+ title="Whisper JAX Transcription",
26
+ description="Upload an audio file to transcribe using Whisper JAX."
27
+ )
28
+
29
+ interface.launch()