csukuangfj
commited on
Commit
·
ea07244
1
Parent(s):
ef89ca3
begin to add model
Browse files
app.py
CHANGED
@@ -22,6 +22,7 @@
|
|
22 |
|
23 |
import logging
|
24 |
import gradio as gr
|
|
|
25 |
|
26 |
title = "# Next-gen Kaldi: Generate subtitles for videos"
|
27 |
|
@@ -51,6 +52,14 @@ css = """
|
|
51 |
"""
|
52 |
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
def build_html_output(s: str, style: str = "result_item_success"):
|
55 |
return f"""
|
56 |
<div class='result'>
|
@@ -63,6 +72,7 @@ def build_html_output(s: str, style: str = "result_item_success"):
|
|
63 |
|
64 |
def process_uploaded_file(
|
65 |
language: str,
|
|
|
66 |
in_filename: str,
|
67 |
):
|
68 |
if in_filename is None or in_filename == "":
|
@@ -82,7 +92,7 @@ demo = gr.Blocks(css=css)
|
|
82 |
|
83 |
with demo:
|
84 |
gr.Markdown(title)
|
85 |
-
language_choices =
|
86 |
|
87 |
language_radio = gr.Radio(
|
88 |
label="Language",
|
@@ -90,12 +100,23 @@ with demo:
|
|
90 |
value=language_choices[0],
|
91 |
)
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
with gr.Tabs():
|
94 |
with gr.TabItem("Upload video from disk"):
|
95 |
uploaded_file = gr.Video(
|
96 |
source="upload",
|
97 |
interactive=True,
|
98 |
-
type="filepath",
|
99 |
label="Upload from disk",
|
100 |
)
|
101 |
upload_button = gr.Button("Submit for recognition")
|
@@ -106,6 +127,7 @@ with demo:
|
|
106 |
process_uploaded_file,
|
107 |
inputs=[
|
108 |
language_radio,
|
|
|
109 |
uploaded_file,
|
110 |
],
|
111 |
outputs=[uploaded_output, uploaded_html_info],
|
|
|
22 |
|
23 |
import logging
|
24 |
import gradio as gr
|
25 |
+
from model import language_to_models
|
26 |
|
27 |
title = "# Next-gen Kaldi: Generate subtitles for videos"
|
28 |
|
|
|
52 |
"""
|
53 |
|
54 |
|
55 |
+
def update_model_dropdown(language: str):
|
56 |
+
if language in language_to_models:
|
57 |
+
choices = language_to_models[language]
|
58 |
+
return gr.Dropdown.update(choices=choices, value=choices[0])
|
59 |
+
|
60 |
+
raise ValueError(f"Unsupported language: {language}")
|
61 |
+
|
62 |
+
|
63 |
def build_html_output(s: str, style: str = "result_item_success"):
|
64 |
return f"""
|
65 |
<div class='result'>
|
|
|
72 |
|
73 |
def process_uploaded_file(
|
74 |
language: str,
|
75 |
+
repo_id: str,
|
76 |
in_filename: str,
|
77 |
):
|
78 |
if in_filename is None or in_filename == "":
|
|
|
92 |
|
93 |
with demo:
|
94 |
gr.Markdown(title)
|
95 |
+
language_choices = list(language_to_models.keys())
|
96 |
|
97 |
language_radio = gr.Radio(
|
98 |
label="Language",
|
|
|
100 |
value=language_choices[0],
|
101 |
)
|
102 |
|
103 |
+
model_dropdown = gr.Dropdown(
|
104 |
+
choices=language_to_models[language_choices[0]],
|
105 |
+
label="Select a model",
|
106 |
+
value=language_to_models[language_choices[0]][0],
|
107 |
+
)
|
108 |
+
|
109 |
+
language_radio.change(
|
110 |
+
update_model_dropdown,
|
111 |
+
inputs=language_radio,
|
112 |
+
outputs=model_dropdown,
|
113 |
+
)
|
114 |
+
|
115 |
with gr.Tabs():
|
116 |
with gr.TabItem("Upload video from disk"):
|
117 |
uploaded_file = gr.Video(
|
118 |
source="upload",
|
119 |
interactive=True,
|
|
|
120 |
label="Upload from disk",
|
121 |
)
|
122 |
upload_button = gr.Button("Submit for recognition")
|
|
|
127 |
process_uploaded_file,
|
128 |
inputs=[
|
129 |
language_radio,
|
130 |
+
model_dropdown,
|
131 |
uploaded_file,
|
132 |
],
|
133 |
outputs=[uploaded_output, uploaded_html_info],
|
model.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2022-2023 Xiaomi Corp. (authors: Fangjun Kuang)
|
2 |
+
#
|
3 |
+
# See LICENSE for clarification regarding multiple authors
|
4 |
+
#
|
5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
# you may not use this file except in compliance with the License.
|
7 |
+
# You may obtain a copy of the License at
|
8 |
+
#
|
9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
#
|
11 |
+
# Unless required by applicable law or agreed to in writing, software
|
12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
# See the License for the specific language governing permissions and
|
15 |
+
# limitations under the License.
|
16 |
+
|
17 |
+
from huggingface_hub import hf_hub_download
|
18 |
+
|
19 |
+
english_models = {
|
20 |
+
"whisper-tiny.en": _get_whisper_model,
|
21 |
+
"whisper-base.en": _get_whisper_model,
|
22 |
+
"whisper-small.en": _get_whisper_model,
|
23 |
+
}
|
24 |
+
|
25 |
+
chinese_english_mixed_models = {
|
26 |
+
"csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28": _get_paraformer_zh_pre_trained_model,
|
27 |
+
}
|
28 |
+
|
29 |
+
russian_models = {
|
30 |
+
"alphacep/vosk-model-ru": _get_russian_pre_trained_model,
|
31 |
+
"alphacep/vosk-model-small-ru": _get_russian_pre_trained_model,
|
32 |
+
}
|
33 |
+
|
34 |
+
language_to_models = {
|
35 |
+
"English": list(english_models.keys()),
|
36 |
+
"Chinese+English": list(chinese_english_mixed_models.keys()),
|
37 |
+
"Russian": list(russian_models.keys()),
|
38 |
+
}
|