jhj0517 commited on
Commit
c1693be
Β·
1 Parent(s): 6669118

Apply yaml to translations

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -5,6 +5,7 @@ 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
  from modules.whisper.whisper_factory import WhisperFactory
9
  from modules.whisper.faster_whisper_inference import FasterWhisperInference
10
  from modules.whisper.insanely_fast_whisper_inference import InsanelyFastWhisperInference
@@ -35,8 +36,7 @@ class App:
35
  self.deepl_api = DeepLAPI(
36
  output_dir=os.path.join(self.args.output_dir, "translations")
37
  )
38
- with open(DEFAULT_PARAMETERS_CONFIG_PATH, 'r', encoding='utf-8') as file:
39
- self.default_params = yaml.safe_load(file)
40
 
41
  def create_whisper_parameters(self):
42
  whisper_params = self.default_params["whisper"]
@@ -180,6 +180,10 @@ class App:
180
  )
181
 
182
  def launch(self):
 
 
 
 
183
  with self.app:
184
  with gr.Row():
185
  with gr.Column():
@@ -264,17 +268,15 @@ class App:
264
 
265
  with gr.TabItem("DeepL API"): # sub tab1
266
  with gr.Row():
267
- tb_authkey = gr.Textbox(label="Your Auth Key (API KEY)",
268
- value="")
269
  with gr.Row():
270
- dd_deepl_sourcelang = gr.Dropdown(label="Source Language", value="Automatic Detection",
271
- choices=list(
272
  self.deepl_api.available_source_langs.keys()))
273
- dd_deepl_targetlang = gr.Dropdown(label="Target Language", value="English",
274
- choices=list(
275
- self.deepl_api.available_target_langs.keys()))
276
  with gr.Row():
277
- cb_deepl_ispro = gr.Checkbox(label="Pro User?", value=False)
278
  with gr.Row():
279
  cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename",
280
  interactive=True)
@@ -286,8 +288,8 @@ class App:
286
  btn_openfolder = gr.Button('πŸ“‚', scale=1)
287
 
288
  btn_run.click(fn=self.deepl_api.translate_deepl,
289
- inputs=[tb_authkey, file_subs, dd_deepl_sourcelang, dd_deepl_targetlang,
290
- cb_deepl_ispro, cb_timestamp],
291
  outputs=[tb_indicator, files_subtitles])
292
 
293
  btn_openfolder.click(fn=lambda: self.open_folder(os.path.join(self.args.output_dir, "translations")),
@@ -296,14 +298,15 @@ class App:
296
 
297
  with gr.TabItem("NLLB"): # sub tab2
298
  with gr.Row():
299
- dd_nllb_model = gr.Dropdown(label="Model", value="facebook/nllb-200-1.3B",
300
  choices=self.nllb_inf.available_models)
301
- dd_nllb_sourcelang = gr.Dropdown(label="Source Language",
302
- choices=self.nllb_inf.available_source_langs)
303
- dd_nllb_targetlang = gr.Dropdown(label="Target Language",
304
- choices=self.nllb_inf.available_target_langs)
305
  with gr.Row():
306
- nb_max_length = gr.Number(label="Max Length Per Line", value=200, precision=0)
 
307
  with gr.Row():
308
  cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename",
309
  interactive=True)
@@ -317,7 +320,7 @@ class App:
317
  md_vram_table = gr.HTML(NLLB_VRAM_TABLE, elem_id="md_nllb_vram_table")
318
 
319
  btn_run.click(fn=self.nllb_inf.translate_file,
320
- inputs=[file_subs, dd_nllb_model, dd_nllb_sourcelang, dd_nllb_targetlang,
321
  nb_max_length, cb_timestamp],
322
  outputs=[tb_indicator, files_subtitles])
323
 
 
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
+ from modules.utils.files_manager import load_yaml
9
  from modules.whisper.whisper_factory import WhisperFactory
10
  from modules.whisper.faster_whisper_inference import FasterWhisperInference
11
  from modules.whisper.insanely_fast_whisper_inference import InsanelyFastWhisperInference
 
36
  self.deepl_api = DeepLAPI(
37
  output_dir=os.path.join(self.args.output_dir, "translations")
38
  )
39
+ self.default_params = load_yaml(DEFAULT_PARAMETERS_CONFIG_PATH)
 
40
 
41
  def create_whisper_parameters(self):
42
  whisper_params = self.default_params["whisper"]
 
180
  )
181
 
182
  def launch(self):
183
+ translation_params = self.default_params["translation"]
184
+ deepl_params = translation_params["deepl"]
185
+ nllb_params = translation_params["nllb"]
186
+
187
  with self.app:
188
  with gr.Row():
189
  with gr.Column():
 
268
 
269
  with gr.TabItem("DeepL API"): # sub tab1
270
  with gr.Row():
271
+ tb_api_key = gr.Textbox(label="Your Auth Key (API KEY)", value=deepl_params["api_key"])
 
272
  with gr.Row():
273
+ dd_source_lang = gr.Dropdown(label="Source Language", value=deepl_params["source_lang"],
274
+ choices=list(
275
  self.deepl_api.available_source_langs.keys()))
276
+ dd_target_lang = gr.Dropdown(label="Target Language", value=deepl_params["target_lang"],
277
+ choices=list(self.deepl_api.available_target_langs.keys()))
 
278
  with gr.Row():
279
+ cb_is_pro = gr.Checkbox(label="Pro User?", value=deepl_params["is_pro"])
280
  with gr.Row():
281
  cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename",
282
  interactive=True)
 
288
  btn_openfolder = gr.Button('πŸ“‚', scale=1)
289
 
290
  btn_run.click(fn=self.deepl_api.translate_deepl,
291
+ inputs=[tb_api_key, file_subs, dd_source_lang, dd_target_lang,
292
+ cb_is_pro, cb_timestamp],
293
  outputs=[tb_indicator, files_subtitles])
294
 
295
  btn_openfolder.click(fn=lambda: self.open_folder(os.path.join(self.args.output_dir, "translations")),
 
298
 
299
  with gr.TabItem("NLLB"): # sub tab2
300
  with gr.Row():
301
+ dd_model_size = gr.Dropdown(label="Model", value=nllb_params["model_size"],
302
  choices=self.nllb_inf.available_models)
303
+ dd_source_lang = gr.Dropdown(label="Source Language", value=nllb_params["source_lang"],
304
+ choices=self.nllb_inf.available_source_langs)
305
+ dd_target_lang = gr.Dropdown(label="Target Language", value=nllb_params["target_lang"],
306
+ choices=self.nllb_inf.available_target_langs)
307
  with gr.Row():
308
+ nb_max_length = gr.Number(label="Max Length Per Line", value=nllb_params["max_length"],
309
+ precision=0)
310
  with gr.Row():
311
  cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename",
312
  interactive=True)
 
320
  md_vram_table = gr.HTML(NLLB_VRAM_TABLE, elem_id="md_nllb_vram_table")
321
 
322
  btn_run.click(fn=self.nllb_inf.translate_file,
323
+ inputs=[file_subs, dd_model_size, dd_source_lang, dd_target_lang,
324
  nb_max_length, cb_timestamp],
325
  outputs=[tb_indicator, files_subtitles])
326