adelechka commited on
Commit
0e97cdb
·
verified ·
1 Parent(s): d8b3de8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ pipe2 = pipeline("automatic-speech-recognition", model="distil-whisper/distil-small.en")
5
+ pipe3 = pipeline("automatic-speech-recognition", model="antony66/whisper-large-v3-russian")
6
+
7
+ demo = gr.Blocks()
8
+
9
+
10
+ def transcribe_speech_english(filepath):
11
+ if filepath is None:
12
+ gr.Warning("No audio found, please retry.")
13
+ return ""
14
+ output = pipe2(filepath)
15
+ return output["text"]
16
+
17
+
18
+ def transcribe_speech_russian(filepath):
19
+ if filepath is None:
20
+ gr.Warning("No audio found, please retry.")
21
+ return ""
22
+ output = pipe3(filepath)
23
+ return output["text"]
24
+
25
+
26
+ mic_transcribe_english = gr.Interface(
27
+ fn=transcribe_speech_english,
28
+ inputs=gr.Audio(sources="microphone",
29
+ type="filepath"),
30
+ outputs=gr.Textbox(label="Transcription",
31
+ lines=3),
32
+ allow_flagging="never")
33
+
34
+
35
+ mic_transcribe_russian = gr.Interface(
36
+ fn=transcribe_speech_russian,
37
+ inputs=gr.Audio(sources="microphone",
38
+ type="filepath"),
39
+ outputs=gr.Textbox(label="Transcription",
40
+ lines=3),
41
+ allow_flagging="never")
42
+
43
+
44
+ file_transcribe_english = gr.Interface(
45
+ fn=transcribe_speech_english,
46
+ inputs=gr.Audio(sources="upload",
47
+ type="filepath"),
48
+ outputs=gr.Textbox(label="Transcription",
49
+ lines=3),
50
+ allow_flagging="never",
51
+ )
52
+
53
+
54
+ file_transcribe_russian = gr.Interface(
55
+ fn=transcribe_speech_russian,
56
+ inputs=gr.Audio(sources="upload",
57
+ type="filepath"),
58
+ outputs=gr.Textbox(label="Transcription",
59
+ lines=3),
60
+ allow_flagging="never",
61
+ )
62
+
63
+
64
+ with demo:
65
+ gr.TabbedInterface(
66
+ [mic_transcribe_english,
67
+ file_transcribe_english,
68
+ mic_transcribe_russian,
69
+ file_transcribe_russian],
70
+ ["Transcribe Microphone English",
71
+ "Transcribe Audio File English",
72
+ "Transcribe Microphone Russian",
73
+ "Transcribe Audio File Russian"],
74
+ )
75
+
76
+ demo.launch()