akhil2808 commited on
Commit
1f9ba8e
1 Parent(s): e921581

Upload 2 files

Browse files
Files changed (2) hide show
  1. app (7).py +100 -0
  2. requirements (3).txt +4 -0
app (7).py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2022 Horizon Robotics. (authors: Binbin Zhang)
2
+ # 2022 Chengdong Liang (liangchengdong@mail.nwpu.edu.cn)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import gradio as gr
17
+ import torch
18
+ from wenet.cli.model import load_model
19
+
20
+
21
+
22
+ def process_cat_embs(cat_embs):
23
+ device = "cpu"
24
+ cat_embs = torch.tensor(
25
+ [float(c) for c in cat_embs.split(',')]).to(device)
26
+ return cat_embs
27
+
28
+
29
+ def download_rev_models():
30
+ from huggingface_hub import hf_hub_download
31
+ import joblib
32
+
33
+ REPO_ID = "Revai/reverb-asr"
34
+
35
+ files = ['reverb_asr_v1.jit.zip', 'tk.units.txt']
36
+ downloaded_files = [hf_hub_download(repo_id=REPO_ID, filename=f) for f in files]
37
+ model = load_model(downloaded_files[0], downloaded_files[1])
38
+ return model
39
+
40
+ model = download_rev_models()
41
+
42
+
43
+ def recognition(audio, style=0):
44
+ if audio is None:
45
+ return "Input Error! Please enter one audio!"
46
+ # NOTE: model supports 16k sample_rate
47
+
48
+ cat_embs = ','.join([str(s) for s in (style, 1-style)])
49
+ cat_embs = process_cat_embs(cat_embs)
50
+ ans = model.transcribe(audio, cat_embs = cat_embs)
51
+
52
+ if ans is None:
53
+ return "ERROR! No text output! Please try again!"
54
+ txt = ans['text']
55
+ txt = txt.replace('▁', ' ')
56
+ return txt
57
+
58
+
59
+ # input
60
+ inputs = [
61
+ gr.inputs.Audio(source="microphone", type="filepath", label='Input audio'),
62
+ gr.Slider(0, 1, value=0, label="Verbatimicity - from non-verbatim (0) to verbatim (1)", info="Choose a transcription style between non-verbatim and verbatim"),
63
+ ]
64
+
65
+ examples = [
66
+ ['examples/POD1000000012_S0000335.wav'],
67
+ ['examples/POD1000000013_S0000062.wav'],
68
+ ['examples/POD1000000032_S0000020.wav'],
69
+ ['examples/POD1000000032_S0000038.wav'],
70
+ ['examples/POD1000000032_S0000050.wav'],
71
+ ['examples/POD1000000032_S0000058.wav'],
72
+ ]
73
+
74
+
75
+ output = gr.outputs.Textbox(label="Output Text")
76
+
77
+ text = "Reverb ASR Transcription Styles Demo"
78
+
79
+ # description
80
+ description = (
81
+ "Reverb ASR supports verbatim and non-verbatim transcription. Try recording an audio with disfluencies (ex: \'uh\', \'um\') and testing both transcription styles. Or, choose an example audio below." # noqa
82
+ )
83
+
84
+ article = (
85
+ "<p style='text-align: center'>"
86
+ "<a href='https://rev.com' target='_blank'>Learn more about Rev</a>" # noqa
87
+ "</p>")
88
+
89
+ interface = gr.Interface(
90
+ fn=recognition,
91
+ inputs=inputs,
92
+ outputs=output,
93
+ title=text,
94
+ description=description,
95
+ article=article,
96
+ examples=examples,
97
+ theme='huggingface',
98
+ )
99
+
100
+ interface.launch(enable_queue=True)
requirements (3).txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ wenet @ git+https://github.com/revdotcom/reverb#subdirectory=asr
2
+ gradio==3.14.0
3
+ joblib~=1.4
4
+ huggingface-hub