csukuangfj
commited on
Commit
•
994c238
1
Parent(s):
d885ec7
add examples
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ from pathlib import Path
|
|
27 |
import gradio as gr
|
28 |
|
29 |
from decode import decode
|
30 |
-
from model import get_pretrained_model, get_vad, language_to_models
|
31 |
|
32 |
title = "# Next-gen Kaldi: Generate subtitles for videos"
|
33 |
|
@@ -56,6 +56,19 @@ css = """
|
|
56 |
.result_item_error {background-color:#ff7070;color:white;align-self:start}
|
57 |
"""
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
def update_model_dropdown(language: str):
|
61 |
if language in language_to_models:
|
@@ -106,8 +119,8 @@ def process_uploaded_file(
|
|
106 |
return (
|
107 |
(in_filename, srt_filename),
|
108 |
srt_filename,
|
109 |
-
result,
|
110 |
build_html_output("Done! Please download the SRT file", "result_item_success"),
|
|
|
111 |
)
|
112 |
|
113 |
|
@@ -146,6 +159,28 @@ with demo:
|
|
146 |
)
|
147 |
upload_button = gr.Button("Submit for recognition")
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
upload_button.click(
|
150 |
process_uploaded_file,
|
151 |
inputs=[
|
@@ -154,10 +189,10 @@ with demo:
|
|
154 |
uploaded_file,
|
155 |
],
|
156 |
outputs=[
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
],
|
162 |
)
|
163 |
|
|
|
27 |
import gradio as gr
|
28 |
|
29 |
from decode import decode
|
30 |
+
from model import get_pretrained_model, get_vad, language_to_models, get_file
|
31 |
|
32 |
title = "# Next-gen Kaldi: Generate subtitles for videos"
|
33 |
|
|
|
56 |
.result_item_error {background-color:#ff7070;color:white;align-self:start}
|
57 |
"""
|
58 |
|
59 |
+
examples = [
|
60 |
+
"President-Obama-on-the-Importance-of-Education.mp4",
|
61 |
+
]
|
62 |
+
|
63 |
+
for name in examples:
|
64 |
+
filename = get_file(
|
65 |
+
"csukuangfj/vad",
|
66 |
+
name,
|
67 |
+
subfolder=".",
|
68 |
+
)
|
69 |
+
|
70 |
+
shutil.copyfile(filename, name)
|
71 |
+
|
72 |
|
73 |
def update_model_dropdown(language: str):
|
74 |
if language in language_to_models:
|
|
|
119 |
return (
|
120 |
(in_filename, srt_filename),
|
121 |
srt_filename,
|
|
|
122 |
build_html_output("Done! Please download the SRT file", "result_item_success"),
|
123 |
+
result,
|
124 |
)
|
125 |
|
126 |
|
|
|
159 |
)
|
160 |
upload_button = gr.Button("Submit for recognition")
|
161 |
|
162 |
+
output_video = gr.Video(label="Output")
|
163 |
+
output_srt_file = gr.File(label="Generated subtitles", show_label=True)
|
164 |
+
|
165 |
+
output_info = gr.HTML(label="Info")
|
166 |
+
output_textbox = gr.Textbox(label="Recognized speech from uploaded file")
|
167 |
+
|
168 |
+
gr.Examples(
|
169 |
+
examples=examples,
|
170 |
+
inputs=[
|
171 |
+
language_radio,
|
172 |
+
model_dropdown,
|
173 |
+
uploaded_file,
|
174 |
+
],
|
175 |
+
outputs=[
|
176 |
+
output_video,
|
177 |
+
output_srt_file,
|
178 |
+
output_info,
|
179 |
+
output_textbox,
|
180 |
+
],
|
181 |
+
fn=process_uploaded_file,
|
182 |
+
)
|
183 |
+
|
184 |
upload_button.click(
|
185 |
process_uploaded_file,
|
186 |
inputs=[
|
|
|
189 |
uploaded_file,
|
190 |
],
|
191 |
outputs=[
|
192 |
+
output_video,
|
193 |
+
output_srt_file,
|
194 |
+
output_info,
|
195 |
+
output_textbox,
|
196 |
],
|
197 |
)
|
198 |
|
model.py
CHANGED
@@ -35,6 +35,9 @@ def _get_nn_model_filename(
|
|
35 |
return nn_model_filename
|
36 |
|
37 |
|
|
|
|
|
|
|
38 |
def _get_bpe_model_filename(
|
39 |
repo_id: str,
|
40 |
filename: str = "bpe.model",
|
|
|
35 |
return nn_model_filename
|
36 |
|
37 |
|
38 |
+
get_file = _get_nn_model_filename
|
39 |
+
|
40 |
+
|
41 |
def _get_bpe_model_filename(
|
42 |
repo_id: str,
|
43 |
filename: str = "bpe.model",
|