anzorq commited on
Commit
fd585a0
1 Parent(s): 31de73c

Add application file

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import whisper
4
+ import time
5
+
6
+ model = whisper.load_model("base")
7
+
8
+ def transcribe(audio, state="", delay=0.2):
9
+ time.sleep(delay)
10
+ result = model.transcribe(audio, language="english")
11
+ state += result['text'] + " "
12
+ # return f"Language: {result['language']}\
13
+ # \n\nText: {state}"
14
+ return state, state
15
+
16
+ def debug(audio, state="", delay=0.2):
17
+ print(whisper.load_audio(audio).shape)
18
+ state += str(whisper.load_audio(audio))
19
+ # print(state)
20
+ return state, state
21
+
22
+ delay_slider = gr.inputs.Slider(minimum=0, maximum=10, default=0.2, label="Delay (seconds)")
23
+
24
+ gr.Interface(
25
+ fn=transcribe,
26
+ # fn=debug,
27
+ inputs=[
28
+ # gr.Audio(source="upload", type="filepath"),
29
+ gr.Audio(source="microphone", type="filepath", streaming=True),
30
+ "state",
31
+ delay_slider
32
+ ],
33
+ outputs=[
34
+ gr.Textbox(label="Transcription", lines=10, max_lines=20),
35
+ "state"
36
+ ],
37
+ live=True,
38
+ allow_flagging='never'
39
+ ).launch()