Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
|
3 |
+
# You can choose your model from - see it on readme file and update the modelname
|
4 |
+
modelname = "base"
|
5 |
+
model = whisper.load_model(modelname)
|
6 |
+
|
7 |
+
import gradio as gr
|
8 |
+
import time
|
9 |
+
|
10 |
+
def SpeechToText(audio):
|
11 |
+
if audio == None : return ""
|
12 |
+
time.sleep(1)
|
13 |
+
|
14 |
+
audio = whisper.load_audio(audio)
|
15 |
+
audio = whisper.pad_or_trim(audio)
|
16 |
+
|
17 |
+
# make log-Mel spectrogram and move to the same device as the model
|
18 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
19 |
+
|
20 |
+
# Detect the Max probability of language ?
|
21 |
+
_, probs = model.detect_language(mel)
|
22 |
+
language = max(probs, key=probs.get)
|
23 |
+
|
24 |
+
# Decode audio to Text
|
25 |
+
options = whisper.DecodingOptions(fp16 = False)
|
26 |
+
result = whisper.decode(model, mel, options)
|
27 |
+
return (language , result.text)
|
28 |
+
|
29 |
+
print("Starting the Gradio Web UI")
|
30 |
+
gr.Interface(
|
31 |
+
title = 'OpenAI Whisper implementation on Gradio Web UI',
|
32 |
+
fn=SpeechToText,
|
33 |
+
|
34 |
+
inputs=[
|
35 |
+
gr.Audio(source="microphone", type="filepath")
|
36 |
+
],
|
37 |
+
outputs=[
|
38 |
+
"label",
|
39 |
+
"textbox",
|
40 |
+
],
|
41 |
+
live=True
|
42 |
+
).launch(
|
43 |
+
debug=False,
|
44 |
+
)
|