taizhehui commited on
Commit
d8a235b
1 Parent(s): 453e180

Create app.py

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