Rich Gregson commited on
Commit
92054a5
1 Parent(s): bff468e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # install whisper
2
+ !pip install git+https://github.com/openai/whisper.git
3
+
4
+ #import whisper & gadio
5
+ import whisper
6
+ import gradio as gr
7
+
8
+ model = whisper.load_model("large")
9
+
10
+ # transcribe functions
11
+
12
+ def transcribe(file):
13
+ options = dict(task="transcribe", best_of=5)
14
+ text = model.transcribe(file, **options)["text"]
15
+ return text.strip()
16
+
17
+ def translate(file):
18
+ options = dict(task="translate", best_of=5)
19
+ text = model.transcribe(file, **options)["text"]
20
+ return text.strip()
21
+
22
+ # gradio
23
+ block = gr.Blocks()
24
+
25
+ with block:
26
+ with gr.Group():
27
+ audio = gr.Audio(
28
+ show_label=False,
29
+ source="microphone",
30
+ type="filepath"
31
+ )
32
+ with gr.Box():
33
+ with gr.Row().style(equal_height=True):
34
+ transcribe_button = gr.Button("Transcribe")
35
+
36
+ textbox = gr.Textbox(show_label=False)
37
+
38
+ transcribe_button.click(transcribe, inputs=[audio], outputs=[textbox])
39
+ translate_button.click(translate, inputs=[audio], outputs=[textbox])
40
+
41
+ block.launch()