csukuangfj commited on
Commit
e4911f7
1 Parent(s): f7cc7c3

small fixes

Browse files
Files changed (2) hide show
  1. app.py +52 -10
  2. model.py +1 -0
app.py CHANGED
@@ -98,6 +98,10 @@ def process_uploaded_file(
98
  logging.info(f"Processing uploaded file: {in_filename}")
99
  show_file_info(in_filename)
100
 
 
 
 
 
101
  recognizer = get_pretrained_model(repo_id)
102
  vad = get_vad()
103
 
@@ -145,32 +149,70 @@ with demo:
145
 
146
  with gr.Tabs():
147
  with gr.TabItem("Upload video from disk"):
148
- uploaded_file = gr.Video(
149
  source="upload",
150
  interactive=True,
151
  label="Upload from disk",
152
  show_share_button=True,
153
  )
154
- upload_button = gr.Button("Submit for recognition")
155
 
156
  output_video = gr.Video(label="Output")
157
- output_srt_file = gr.File(label="Generated subtitles", show_label=True)
 
 
 
 
 
 
 
158
 
159
- output_info = gr.HTML(label="Info")
160
- output_textbox = gr.Textbox(label="Recognized speech from uploaded file")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
- upload_button.click(
163
  process_uploaded_file,
164
  inputs=[
165
  language_radio,
166
  model_dropdown,
167
- uploaded_file,
168
  ],
169
  outputs=[
170
  output_video,
171
- output_srt_file,
172
- output_info,
173
- output_textbox,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  ],
175
  )
176
 
 
98
  logging.info(f"Processing uploaded file: {in_filename}")
99
  show_file_info(in_filename)
100
 
101
+ return process(language, repo_id, in_filename)
102
+
103
+
104
+ def process(language: str, repo_id: str, in_filename: str):
105
  recognizer = get_pretrained_model(repo_id)
106
  vad = get_vad()
107
 
 
149
 
150
  with gr.Tabs():
151
  with gr.TabItem("Upload video from disk"):
152
+ uploaded_video_file = gr.Video(
153
  source="upload",
154
  interactive=True,
155
  label="Upload from disk",
156
  show_share_button=True,
157
  )
158
+ upload_video_button = gr.Button("Submit for recognition")
159
 
160
  output_video = gr.Video(label="Output")
161
+ output_srt_file_video = gr.File(
162
+ label="Generated subtitles", show_label=True
163
+ )
164
+
165
+ output_info_video = gr.HTML(label="Info")
166
+ output_textbox_video = gr.Textbox(
167
+ label="Recognized speech from uploaded video file"
168
+ )
169
 
170
+ with gr.TabItem("Upload audio from disk"):
171
+ uploaded_audio_file = gr.Audio(
172
+ source="upload", # Choose between "microphone", "upload"
173
+ type="filepath",
174
+ optional=False,
175
+ label="Upload audio from disk",
176
+ )
177
+ upload_audio_button = gr.Button("Submit for recognition")
178
+
179
+ output_audio = gr.Video(label="Output")
180
+ output_srt_file_audio = gr.File(
181
+ label="Generated subtitles", show_label=True
182
+ )
183
+
184
+ output_info_audio = gr.HTML(label="Info")
185
+ output_textbox_audio = gr.Textbox(
186
+ label="Recognized speech from uploaded audio file"
187
+ )
188
 
189
+ upload_video_button.click(
190
  process_uploaded_file,
191
  inputs=[
192
  language_radio,
193
  model_dropdown,
194
+ uploaded_video_file,
195
  ],
196
  outputs=[
197
  output_video,
198
+ output_srt_file_video,
199
+ output_info_video,
200
+ output_textbox_video,
201
+ ],
202
+ )
203
+
204
+ upload_audio_button.click(
205
+ process_uploaded_file,
206
+ inputs=[
207
+ language_radio,
208
+ model_dropdown,
209
+ uploaded_audio_file,
210
+ ],
211
+ outputs=[
212
+ output_audio,
213
+ output_srt_file_audio,
214
+ output_info_audio,
215
+ output_textbox_audio,
216
  ],
217
  )
218
 
model.py CHANGED
@@ -321,6 +321,7 @@ def _get_english_model(repo_id: str) -> sherpa_onnx.OfflineRecognizer:
321
 
322
 
323
  chinese_models = {
 
324
  "csukuangfj/sherpa-onnx-conformer-zh-stateless2-2023-05-23": _get_wenetspeech_pre_trained_model, # noqa
325
  "zrjin/sherpa-onnx-zipformer-multi-zh-hans-2023-9-2": _get_multi_zh_hans_pre_trained_model, # noqa
326
  }
 
321
 
322
 
323
  chinese_models = {
324
+ "csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28": _get_paraformer_zh_pre_trained_model,
325
  "csukuangfj/sherpa-onnx-conformer-zh-stateless2-2023-05-23": _get_wenetspeech_pre_trained_model, # noqa
326
  "zrjin/sherpa-onnx-zipformer-multi-zh-hans-2023-9-2": _get_multi_zh_hans_pre_trained_model, # noqa
327
  }