theodotus commited on
Commit
4a8a770
1 Parent(s): 094dbb0
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import nemo.collections.asr as nemo_asr
2
+ import gradio as gr
3
+
4
+
5
+
6
+
7
+ asr_model = nemo_asr.models.ASRModel.from_pretrained("theodotus/stt_ua_fastconformer_hybrid_large_pc", map_location="cpu")
8
+
9
+
10
+
11
+
12
+ def process_file(in_filename: str,):
13
+ if in_filename is None or in_filename == "":
14
+ return "Error: No file"
15
+
16
+ transcript = asr_model.transcribe([in_filename])[0][0]
17
+
18
+
19
+ return transcript
20
+
21
+
22
+
23
+
24
+ demo = gr.Blocks()
25
+
26
+ with demo:
27
+ with gr.Tabs():
28
+ with gr.TabItem("Upload from disk"):
29
+ uploaded_file = gr.Audio(
30
+ source="upload", # Choose between "microphone", "upload"
31
+ type="filepath",
32
+ optional=False,
33
+ label="Upload from disk",
34
+ )
35
+ upload_button = gr.Button("Submit for recognition")
36
+ uploaded_output = gr.Textbox(label="Recognized speech from uploaded file")
37
+
38
+ with gr.TabItem("Record from microphone"):
39
+ microphone = gr.Audio(
40
+ source="microphone", # Choose between "microphone", "upload"
41
+ type="filepath",
42
+ optional=False,
43
+ label="Record from microphone",
44
+ )
45
+
46
+ record_button = gr.Button("Submit for recognition")
47
+ recorded_output = gr.Textbox(label="Recognized speech from recordings")
48
+
49
+ upload_button.click(
50
+ process_file,
51
+ inputs=[
52
+ uploaded_file,
53
+ ],
54
+ outputs=[uploaded_output],
55
+ )
56
+
57
+ record_button.click(
58
+ process_file,
59
+ inputs=[
60
+ microphone,
61
+ ],
62
+ outputs=[recorded_output],
63
+ )
64
+
65
+
66
+ if __name__ == "__main__":
67
+ demo.launch()