abcdofbigdata commited on
Commit
8cff660
1 Parent(s): 5ca888f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ asr = pipeline(task="automatic-speech-recognition",
5
+ model="distil-whisper/distil-small.en")
6
+ demo = gr.Blocks()
7
+
8
+ def transcribe_speech(filepath):
9
+ if filepath is None:
10
+ gr.Warning("No audio found, please retry.")
11
+ return ""
12
+ output = asr(filepath)
13
+ return output["text"]
14
+
15
+
16
+ mic_transcribe = gr.Interface(
17
+ fn=transcribe_speech,
18
+ inputs=gr.Audio(sources="microphone",
19
+ type="filepath"),
20
+ outputs=gr.Textbox(label="Transcription",
21
+ lines=3),
22
+ allow_flagging="never")
23
+
24
+ file_transcribe = gr.Interface(
25
+ fn=transcribe_speech,
26
+ inputs=gr.Audio(sources="upload",
27
+ type="filepath"),
28
+ outputs=gr.Textbox(label="Transcription",
29
+ lines=3),
30
+ allow_flagging="never",
31
+ )
32
+
33
+ with demo:
34
+ gr.TabbedInterface(
35
+ [mic_transcribe,
36
+ file_transcribe],
37
+ ["Transcribe Microphone",
38
+ "Transcribe Audio File"],
39
+ )
40
+
41
+ demo.launch(share=True)
42
+