awebdesigner09 commited on
Commit
eb43618
·
verified ·
1 Parent(s): 6abd236

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
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
+ mic_transcribe = gr.Interface(
16
+ fn=transcribe_speech,
17
+ inputs=gr.Audio(sources="microphone",
18
+ type="filepath"),
19
+ outputs=gr.Textbox(label="Transcription",
20
+ lines=3),
21
+ allow_flagging="never")
22
+
23
+ file_transcribe = gr.Interface(
24
+ fn=transcribe_speech,
25
+ inputs=gr.Audio(sources="upload",
26
+ type="filepath"),
27
+ outputs=gr.Textbox(label="Transcription",
28
+ lines=3),
29
+ allow_flagging="never",
30
+ )
31
+
32
+ with demo:
33
+ gr.TabbedInterface(
34
+ [mic_transcribe,
35
+ file_transcribe],
36
+ ["Transcribe Microphone",
37
+ "Transcribe Audio File"],
38
+ )
39
+
40
+ demo.launch()