Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install git+https://github.com/openai/whisper.git")
|
3 |
+
import gradio as gr
|
4 |
+
import whisper
|
5 |
+
|
6 |
+
def transcribe_audio(audio):
|
7 |
+
# Load the audio and trim/pad it to fit for 30 seconds
|
8 |
+
audio = whisper.load_audio(audio)
|
9 |
+
audio = whisper.pad_or_trim(audio)
|
10 |
+
|
11 |
+
# Make mel log spectrogram
|
12 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
13 |
+
|
14 |
+
# Detect the spoken language
|
15 |
+
_, probs = model.detect_language(mel)
|
16 |
+
|
17 |
+
# Decode the audio
|
18 |
+
options = whisper.DecodingOptions()
|
19 |
+
result = whisper.decode(model, mel, options)
|
20 |
+
|
21 |
+
return result.text
|
22 |
+
|
23 |
+
title = "Automatic Speech Recognition"
|
24 |
+
description = "Speech to Text Conversion using whisper"
|
25 |
+
|
26 |
+
# Input from user
|
27 |
+
in_prompt = gradio.components.Audio(source="microphone", type="filepath")
|
28 |
+
|
29 |
+
# Output response
|
30 |
+
out_response = gradio.components.Textbox(label='Text')
|
31 |
+
|
32 |
+
# Gradio interface to generate UI link
|
33 |
+
iface = gradio.Interface(fn=transcribe_audio,
|
34 |
+
inputs = in_prompt,
|
35 |
+
outputs = out_response,
|
36 |
+
title=title,
|
37 |
+
description=description,
|
38 |
+
live=True
|
39 |
+
)
|
40 |
+
|
41 |
+
iface.launch(debug = True)
|