amrelshall commited on
Commit
f6ed4b1
1 Parent(s): 9f5db98

Create app.py

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