MusIre commited on
Commit
6e25342
β€’
1 Parent(s): 987ea19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -25
app.py CHANGED
@@ -1,32 +1,24 @@
1
- import subprocess
2
-
3
- subprocess.run(["pip", "install", "datasets"])
4
- subprocess.run(["pip", "install", "transformers"])
5
- subprocess.run(["pip", "install", "torch", "torchvision", "torchaudio", "-f", "https://download.pytorch.org/whl/torch_stable.html"])
6
-
7
  import gradio as gr
8
- from transformers import WhisperProcessor, WhisperForConditionalGeneration
9
 
10
- # Load model and processor
11
- processor = WhisperProcessor.from_pretrained("openai/whisper-large")
12
- model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")
13
- model.config.forced_decoder_ids = None
14
 
15
- # Custom preprocessing function
16
- def preprocess_audio(audio_data):
17
- # Apply any custom preprocessing to the audio data here if needed
18
- return processor(audio_data, return_tensors="pt").input_features
19
 
20
- # Function to perform ASR on audio data
21
- def transcribe_audio(input_features):
22
- # Generate token ids
23
- predicted_ids = model.generate(input_features)
24
 
25
- # Decode token ids to text
26
- transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
 
 
27
 
28
- return transcription[0]
 
29
 
30
- # Create Gradio interface
31
- audio_input = gr.Audio(preprocess=preprocess_audio)
32
- gr.Interface(fn=transcribe_audio, inputs=audio_input, outputs="text").launch()
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import whisper
3
 
 
 
 
 
4
 
5
+ def transcribe_audio(audio_file):
6
+ model = whisper.load_model("base")
7
+ result = model.transcribe(audio_file)
8
+ return result["text"]
9
 
10
+
11
+ def main():
12
+ audio_input = gr.inputs.Audio(source="upload", type="filepath")
13
+ output_text = gr.outputs.Textbox()
14
 
15
+ iface = gr.Interface(fn=transcribe_audio, inputs=audio_input,
16
+ outputs=output_text, title="Audio Transcription App",
17
+ description="Upload an audio file and hit the 'Submit'\
18
+ button")
19
 
20
+ iface.launch()
21
+
22
 
23
+ if __name__ == '__main__':
24
+ main()