jhj0517 commited on
Commit
4e9280e
Β·
1 Parent(s): 2699a55

Apply i18n

Browse files
Files changed (1) hide show
  1. app.py +159 -153
app.py CHANGED
@@ -1,11 +1,13 @@
1
  import os
2
  import argparse
3
  import gradio as gr
 
4
  import yaml
5
 
6
  from modules.utils.paths import (FASTER_WHISPER_MODELS_DIR, DIARIZATION_MODELS_DIR, OUTPUT_DIR, WHISPER_MODELS_DIR,
7
  INSANELY_FAST_WHISPER_MODELS_DIR, NLLB_MODELS_DIR, DEFAULT_PARAMETERS_CONFIG_PATH,
8
- UVR_MODELS_DIR)
 
9
  from modules.utils.files_manager import load_yaml
10
  from modules.whisper.whisper_factory import WhisperFactory
11
  from modules.whisper.faster_whisper_inference import FasterWhisperInference
@@ -22,6 +24,7 @@ class App:
22
  def __init__(self, args):
23
  self.args = args
24
  self.app = gr.Blocks(css=CSS, theme=self.args.theme, delete_cache=(60, 3600))
 
25
  self.whisper_inf = WhisperFactory.create_whisper_inference(
26
  whisper_type=self.args.whisper_type,
27
  whisper_model_dir=self.args.whisper_model_dir,
@@ -213,179 +216,182 @@ class App:
213
  uvr_params = self.default_params["bgm_separation"]
214
 
215
  with self.app:
216
- with gr.Row():
217
- with gr.Column():
218
- gr.Markdown(MARKDOWN, elem_id="md_project")
219
- with gr.Tabs():
220
- with gr.TabItem("File"): # tab1
221
  with gr.Column():
222
- input_file = gr.Files(type="filepath", label="Upload File here")
223
- tb_input_folder = gr.Textbox(label="Input Folder Path (Optional)",
224
- info="Optional: Specify the folder path where the input files are located, if you prefer to use local files instead of uploading them."
225
- " Leave this field empty if you do not wish to use a local path.",
226
- visible=self.args.colab,
227
- value="")
228
-
229
- whisper_params, dd_file_format, cb_timestamp = self.create_whisper_parameters()
230
-
231
- with gr.Row():
232
- btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
233
- with gr.Row():
234
- tb_indicator = gr.Textbox(label="Output", scale=5)
235
- files_subtitles = gr.Files(label="Downloadable output file", scale=3, interactive=False)
236
- btn_openfolder = gr.Button('πŸ“‚', scale=1)
237
-
238
- params = [input_file, tb_input_folder, dd_file_format, cb_timestamp]
239
- btn_run.click(fn=self.whisper_inf.transcribe_file,
240
- inputs=params + whisper_params.as_list(),
241
- outputs=[tb_indicator, files_subtitles])
242
- btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
243
-
244
- with gr.TabItem("Youtube"): # tab2
245
- with gr.Row():
246
- tb_youtubelink = gr.Textbox(label="Youtube Link")
247
- with gr.Row(equal_height=True):
248
  with gr.Column():
249
- img_thumbnail = gr.Image(label="Youtube Thumbnail")
250
- with gr.Column():
251
- tb_title = gr.Label(label="Youtube Title")
252
- tb_description = gr.Textbox(label="Youtube Description", max_lines=15)
 
 
253
 
254
- whisper_params, dd_file_format, cb_timestamp = self.create_whisper_parameters()
255
 
256
- with gr.Row():
257
- btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
258
- with gr.Row():
259
- tb_indicator = gr.Textbox(label="Output", scale=5)
260
- files_subtitles = gr.Files(label="Downloadable output file", scale=3)
261
- btn_openfolder = gr.Button('πŸ“‚', scale=1)
262
 
263
- params = [tb_youtubelink, dd_file_format, cb_timestamp]
 
 
 
 
264
 
265
- btn_run.click(fn=self.whisper_inf.transcribe_youtube,
266
- inputs=params + whisper_params.as_list(),
267
- outputs=[tb_indicator, files_subtitles])
268
- tb_youtubelink.change(get_ytmetas, inputs=[tb_youtubelink],
269
- outputs=[img_thumbnail, tb_title, tb_description])
270
- btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
 
 
 
271
 
272
- with gr.TabItem("Mic"): # tab3
273
- with gr.Row():
274
- mic_input = gr.Microphone(label="Record with Mic", type="filepath", interactive=True)
275
 
276
- whisper_params, dd_file_format, cb_timestamp = self.create_whisper_parameters()
 
 
 
 
 
277
 
278
- with gr.Row():
279
- btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
280
- with gr.Row():
281
- tb_indicator = gr.Textbox(label="Output", scale=5)
282
- files_subtitles = gr.Files(label="Downloadable output file", scale=3)
283
- btn_openfolder = gr.Button('πŸ“‚', scale=1)
284
 
285
- params = [mic_input, dd_file_format, cb_timestamp]
 
 
 
 
 
286
 
287
- btn_run.click(fn=self.whisper_inf.transcribe_mic,
288
- inputs=params + whisper_params.as_list(),
289
- outputs=[tb_indicator, files_subtitles])
290
- btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
291
 
292
- with gr.TabItem("T2T Translation"): # tab 4
293
- with gr.Row():
294
- file_subs = gr.Files(type="filepath", label="Upload Subtitle Files to translate here")
295
 
296
- with gr.TabItem("DeepL API"): # sub tab1
297
- with gr.Row():
298
- tb_api_key = gr.Textbox(label="Your Auth Key (API KEY)", value=deepl_params["api_key"])
299
- with gr.Row():
300
- dd_source_lang = gr.Dropdown(label="Source Language", value=deepl_params["source_lang"],
301
- choices=list(self.deepl_api.available_source_langs.keys()))
302
- dd_target_lang = gr.Dropdown(label="Target Language", value=deepl_params["target_lang"],
303
- choices=list(self.deepl_api.available_target_langs.keys()))
304
  with gr.Row():
305
- cb_is_pro = gr.Checkbox(label="Pro User?", value=deepl_params["is_pro"])
306
  with gr.Row():
307
- cb_timestamp = gr.Checkbox(value=translation_params["add_timestamp"], label="Add a timestamp to the end of the filename",
308
- interactive=True)
309
- with gr.Row():
310
- btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
311
- with gr.Row():
312
- tb_indicator = gr.Textbox(label="Output", scale=5)
313
- files_subtitles = gr.Files(label="Downloadable output file", scale=3)
314
  btn_openfolder = gr.Button('πŸ“‚', scale=1)
315
 
316
- btn_run.click(fn=self.deepl_api.translate_deepl,
317
- inputs=[tb_api_key, file_subs, dd_source_lang, dd_target_lang,
318
- cb_is_pro, cb_timestamp],
319
- outputs=[tb_indicator, files_subtitles])
320
 
321
- btn_openfolder.click(fn=lambda: self.open_folder(os.path.join(self.args.output_dir, "translations")),
322
- inputs=None,
323
- outputs=None)
 
324
 
325
- with gr.TabItem("NLLB"): # sub tab2
326
- with gr.Row():
327
- dd_model_size = gr.Dropdown(label="Model", value=nllb_params["model_size"],
328
- choices=self.nllb_inf.available_models)
329
- dd_source_lang = gr.Dropdown(label="Source Language", value=nllb_params["source_lang"],
330
- choices=self.nllb_inf.available_source_langs)
331
- dd_target_lang = gr.Dropdown(label="Target Language", value=nllb_params["target_lang"],
332
- choices=self.nllb_inf.available_target_langs)
333
- with gr.Row():
334
- nb_max_length = gr.Number(label="Max Length Per Line", value=nllb_params["max_length"],
335
- precision=0)
336
- with gr.Row():
337
- cb_timestamp = gr.Checkbox(value=translation_params["add_timestamp"], label="Add a timestamp to the end of the filename",
338
- interactive=True)
339
  with gr.Row():
340
- btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
341
- with gr.Row():
342
- tb_indicator = gr.Textbox(label="Output", scale=5)
343
- files_subtitles = gr.Files(label="Downloadable output file", scale=3)
344
- btn_openfolder = gr.Button('πŸ“‚', scale=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  with gr.Column():
346
- md_vram_table = gr.HTML(NLLB_VRAM_TABLE, elem_id="md_nllb_vram_table")
347
-
348
- btn_run.click(fn=self.nllb_inf.translate_file,
349
- inputs=[file_subs, dd_model_size, dd_source_lang, dd_target_lang,
350
- nb_max_length, cb_timestamp],
351
- outputs=[tb_indicator, files_subtitles])
352
-
353
- btn_openfolder.click(fn=lambda: self.open_folder(os.path.join(self.args.output_dir, "translations")),
354
- inputs=None,
355
- outputs=None)
356
-
357
- with gr.TabItem("BGM Separation"):
358
- files_audio = gr.Files(type="filepath", label="Upload Audio Files to separate background music")
359
- dd_uvr_device = gr.Dropdown(label="Device", value=self.whisper_inf.music_separator.device,
360
- choices=self.whisper_inf.music_separator.available_devices)
361
- dd_uvr_model_size = gr.Dropdown(label="Model", value=uvr_params["model_size"],
362
- choices=self.whisper_inf.music_separator.available_models)
363
- nb_uvr_segment_size = gr.Number(label="Segment Size", value=uvr_params["segment_size"], precision=0)
364
- cb_uvr_save_file = gr.Checkbox(label="Save separated files to output",
365
- value=True, visible=False)
366
- btn_run = gr.Button("SEPARATE BACKGROUND MUSIC", variant="primary")
367
- with gr.Column():
368
- with gr.Row():
369
- ad_instrumental = gr.Audio(label="Instrumental", scale=8)
370
- btn_open_instrumental_folder = gr.Button('πŸ“‚', scale=1)
371
- with gr.Row():
372
- ad_vocals = gr.Audio(label="Vocals", scale=8)
373
- btn_open_vocals_folder = gr.Button('πŸ“‚', scale=1)
374
-
375
- btn_run.click(fn=self.whisper_inf.music_separator.separate_files,
376
- inputs=[files_audio, dd_uvr_model_size, dd_uvr_device, nb_uvr_segment_size,
377
- cb_uvr_save_file],
378
- outputs=[ad_instrumental, ad_vocals])
379
- btn_open_instrumental_folder.click(inputs=None,
380
- outputs=None,
381
- fn=lambda: self.open_folder(os.path.join(
382
- self.args.output_dir, "UVR", "instrumental"
383
- )))
384
- btn_open_vocals_folder.click(inputs=None,
385
- outputs=None,
386
- fn=lambda: self.open_folder(os.path.join(
387
- self.args.output_dir, "UVR", "vocals"
388
- )))
389
 
390
  # Launch the app with optional gradio settings
391
  args = self.args
 
1
  import os
2
  import argparse
3
  import gradio as gr
4
+ from gradio_i18n import Translate, gettext as _
5
  import yaml
6
 
7
  from modules.utils.paths import (FASTER_WHISPER_MODELS_DIR, DIARIZATION_MODELS_DIR, OUTPUT_DIR, WHISPER_MODELS_DIR,
8
  INSANELY_FAST_WHISPER_MODELS_DIR, NLLB_MODELS_DIR, DEFAULT_PARAMETERS_CONFIG_PATH,
9
+ UVR_MODELS_DIR, I18N_YAML_PATH)
10
+ from modules.utils.constants import AUTOMATIC_DETECTION
11
  from modules.utils.files_manager import load_yaml
12
  from modules.whisper.whisper_factory import WhisperFactory
13
  from modules.whisper.faster_whisper_inference import FasterWhisperInference
 
24
  def __init__(self, args):
25
  self.args = args
26
  self.app = gr.Blocks(css=CSS, theme=self.args.theme, delete_cache=(60, 3600))
27
+ self.i18n = Translate(I18N_YAML_PATH)
28
  self.whisper_inf = WhisperFactory.create_whisper_inference(
29
  whisper_type=self.args.whisper_type,
30
  whisper_model_dir=self.args.whisper_model_dir,
 
216
  uvr_params = self.default_params["bgm_separation"]
217
 
218
  with self.app:
219
+ with self.i18n:
220
+ with gr.Row():
 
 
 
221
  with gr.Column():
222
+ gr.Markdown(MARKDOWN, elem_id="md_project")
223
+ with gr.Tabs():
224
+ with gr.TabItem(_("File")): # tab1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  with gr.Column():
226
+ input_file = gr.Files(type="filepath", label=_("Upload File here"))
227
+ tb_input_folder = gr.Textbox(label="Input Folder Path (Optional)",
228
+ info="Optional: Specify the folder path where the input files are located, if you prefer to use local files instead of uploading them."
229
+ " Leave this field empty if you do not wish to use a local path.",
230
+ visible=self.args.colab,
231
+ value="")
232
 
233
+ whisper_params, dd_file_format, cb_timestamp = self.create_whisper_parameters()
234
 
235
+ with gr.Row():
236
+ btn_run = gr.Button(_("GENERATE SUBTITLE FILE"), variant="primary")
237
+ with gr.Row():
238
+ tb_indicator = gr.Textbox(label=_("Output"), scale=5)
239
+ files_subtitles = gr.Files(label=_("Downloadable output file"), scale=3, interactive=False)
240
+ btn_openfolder = gr.Button('πŸ“‚', scale=1)
241
 
242
+ params = [input_file, tb_input_folder, dd_file_format, cb_timestamp]
243
+ btn_run.click(fn=self.whisper_inf.transcribe_file,
244
+ inputs=params + whisper_params.as_list(),
245
+ outputs=[tb_indicator, files_subtitles])
246
+ btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
247
 
248
+ with gr.TabItem(_("Youtube")): # tab2
249
+ with gr.Row():
250
+ tb_youtubelink = gr.Textbox(label=_("Youtube Link"))
251
+ with gr.Row(equal_height=True):
252
+ with gr.Column():
253
+ img_thumbnail = gr.Image(label=_("Youtube Thumbnail"))
254
+ with gr.Column():
255
+ tb_title = gr.Label(label=_("Youtube Title"))
256
+ tb_description = gr.Textbox(label=_("Youtube Description"), max_lines=15)
257
 
258
+ whisper_params, dd_file_format, cb_timestamp = self.create_whisper_parameters()
 
 
259
 
260
+ with gr.Row():
261
+ btn_run = gr.Button(_("GENERATE SUBTITLE FILE"), variant="primary")
262
+ with gr.Row():
263
+ tb_indicator = gr.Textbox(label=_("Output"), scale=5)
264
+ files_subtitles = gr.Files(label=_("Downloadable output file"), scale=3)
265
+ btn_openfolder = gr.Button('πŸ“‚', scale=1)
266
 
267
+ params = [tb_youtubelink, dd_file_format, cb_timestamp]
 
 
 
 
 
268
 
269
+ btn_run.click(fn=self.whisper_inf.transcribe_youtube,
270
+ inputs=params + whisper_params.as_list(),
271
+ outputs=[tb_indicator, files_subtitles])
272
+ tb_youtubelink.change(get_ytmetas, inputs=[tb_youtubelink],
273
+ outputs=[img_thumbnail, tb_title, tb_description])
274
+ btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
275
 
276
+ with gr.TabItem(_("Mic")): # tab3
277
+ with gr.Row():
278
+ mic_input = gr.Microphone(label=_("Record with Mic"), type="filepath", interactive=True)
 
279
 
280
+ whisper_params, dd_file_format, cb_timestamp = self.create_whisper_parameters()
 
 
281
 
 
 
 
 
 
 
 
 
282
  with gr.Row():
283
+ btn_run = gr.Button(_("GENERATE SUBTITLE FILE"), variant="primary")
284
  with gr.Row():
285
+ tb_indicator = gr.Textbox(label=_("Output"), scale=5)
286
+ files_subtitles = gr.Files(label=_("Downloadable output file"), scale=3)
 
 
 
 
 
287
  btn_openfolder = gr.Button('πŸ“‚', scale=1)
288
 
289
+ params = [mic_input, dd_file_format, cb_timestamp]
 
 
 
290
 
291
+ btn_run.click(fn=self.whisper_inf.transcribe_mic,
292
+ inputs=params + whisper_params.as_list(),
293
+ outputs=[tb_indicator, files_subtitles])
294
+ btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
295
 
296
+ with gr.TabItem(_("T2T Translation")): # tab 4
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  with gr.Row():
298
+ file_subs = gr.Files(type="filepath", label="Upload Subtitle Files to translate here")
299
+
300
+ with gr.TabItem(_("DeepL API")): # sub tab1
301
+ with gr.Row():
302
+ tb_api_key = gr.Textbox(label=_("Your Auth Key (API KEY)"), value=deepl_params["api_key"])
303
+ with gr.Row():
304
+ dd_source_lang = gr.Dropdown(label=_("Source Language"), value=deepl_params["source_lang"],
305
+ choices=list(self.deepl_api.available_source_langs.keys()))
306
+ dd_target_lang = gr.Dropdown(label=_("Target Language"), value=deepl_params["target_lang"],
307
+ choices=list(self.deepl_api.available_target_langs.keys()))
308
+ with gr.Row():
309
+ cb_is_pro = gr.Checkbox(label=_("Pro User?"), value=deepl_params["is_pro"])
310
+ with gr.Row():
311
+ cb_timestamp = gr.Checkbox(value=translation_params["add_timestamp"],
312
+ label=_("Add a timestamp to the end of the filename"),
313
+ interactive=True)
314
+ with gr.Row():
315
+ btn_run = gr.Button(_("TRANSLATE SUBTITLE FILE"), variant="primary")
316
+ with gr.Row():
317
+ tb_indicator = gr.Textbox(label=_("Output"), scale=5)
318
+ files_subtitles = gr.Files(label=_("Downloadable output file"), scale=3)
319
+ btn_openfolder = gr.Button('πŸ“‚', scale=1)
320
+
321
+ btn_run.click(fn=self.deepl_api.translate_deepl,
322
+ inputs=[tb_api_key, file_subs, dd_source_lang, dd_target_lang,
323
+ cb_is_pro, cb_timestamp],
324
+ outputs=[tb_indicator, files_subtitles])
325
+
326
+ btn_openfolder.click(fn=lambda: self.open_folder(os.path.join(self.args.output_dir, "translations")),
327
+ inputs=None,
328
+ outputs=None)
329
+
330
+ with gr.TabItem(_("NLLB")): # sub tab2
331
+ with gr.Row():
332
+ dd_model_size = gr.Dropdown(label=_("Model"), value=nllb_params["model_size"],
333
+ choices=self.nllb_inf.available_models)
334
+ dd_source_lang = gr.Dropdown(label=_("Source Language"), value=nllb_params["source_lang"],
335
+ choices=self.nllb_inf.available_source_langs)
336
+ dd_target_lang = gr.Dropdown(label=_("Target Language"), value=nllb_params["target_lang"],
337
+ choices=self.nllb_inf.available_target_langs)
338
+ with gr.Row():
339
+ nb_max_length = gr.Number(label="Max Length Per Line", value=nllb_params["max_length"],
340
+ precision=0)
341
+ with gr.Row():
342
+ cb_timestamp = gr.Checkbox(value=translation_params["add_timestamp"],
343
+ label=_("Add a timestamp to the end of the filename"),
344
+ interactive=True)
345
+ with gr.Row():
346
+ btn_run = gr.Button(_("TRANSLATE SUBTITLE FILE"), variant="primary")
347
+ with gr.Row():
348
+ tb_indicator = gr.Textbox(label=_("Output"), scale=5)
349
+ files_subtitles = gr.Files(label=_("Downloadable output file"), scale=3)
350
+ btn_openfolder = gr.Button('πŸ“‚', scale=1)
351
+ with gr.Column():
352
+ md_vram_table = gr.HTML(NLLB_VRAM_TABLE, elem_id="md_nllb_vram_table")
353
+
354
+ btn_run.click(fn=self.nllb_inf.translate_file,
355
+ inputs=[file_subs, dd_model_size, dd_source_lang, dd_target_lang,
356
+ nb_max_length, cb_timestamp],
357
+ outputs=[tb_indicator, files_subtitles])
358
+
359
+ btn_openfolder.click(fn=lambda: self.open_folder(os.path.join(self.args.output_dir, "translations")),
360
+ inputs=None,
361
+ outputs=None)
362
+
363
+ with gr.TabItem(_("BGM Separation")):
364
+ files_audio = gr.Files(type="filepath", label="Upload Audio Files to separate background music")
365
+ dd_uvr_device = gr.Dropdown(label=_("Device"), value=self.whisper_inf.music_separator.device,
366
+ choices=self.whisper_inf.music_separator.available_devices)
367
+ dd_uvr_model_size = gr.Dropdown(label=_("Model"), value=uvr_params["model_size"],
368
+ choices=self.whisper_inf.music_separator.available_models)
369
+ nb_uvr_segment_size = gr.Number(label="Segment Size", value=uvr_params["segment_size"], precision=0)
370
+ cb_uvr_save_file = gr.Checkbox(label=_("Save separated files to output"),
371
+ value=True, visible=False)
372
+ btn_run = gr.Button(_("SEPARATE BACKGROUND MUSIC"), variant="primary")
373
  with gr.Column():
374
+ with gr.Row():
375
+ ad_instrumental = gr.Audio(label=_("Instrumental"), scale=8)
376
+ btn_open_instrumental_folder = gr.Button('πŸ“‚', scale=1)
377
+ with gr.Row():
378
+ ad_vocals = gr.Audio(label=_("Vocals"), scale=8)
379
+ btn_open_vocals_folder = gr.Button('πŸ“‚', scale=1)
380
+
381
+ btn_run.click(fn=self.whisper_inf.music_separator.separate_files,
382
+ inputs=[files_audio, dd_uvr_model_size, dd_uvr_device, nb_uvr_segment_size,
383
+ cb_uvr_save_file],
384
+ outputs=[ad_instrumental, ad_vocals])
385
+ btn_open_instrumental_folder.click(inputs=None,
386
+ outputs=None,
387
+ fn=lambda: self.open_folder(os.path.join(
388
+ self.args.output_dir, "UVR", "instrumental"
389
+ )))
390
+ btn_open_vocals_folder.click(inputs=None,
391
+ outputs=None,
392
+ fn=lambda: self.open_folder(os.path.join(
393
+ self.args.output_dir, "UVR", "vocals"
394
+ )))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
 
396
  # Launch the app with optional gradio settings
397
  args = self.args