jhj0517 commited on
Commit
43820de
β€’
1 Parent(s): 379621f

added NLLB translation

Browse files
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import gradio as gr
2
  from modules.whisper_Inference import WhisperInference
 
3
  import os
4
- from ui.htmls import CSS, MARKDOWN
5
  from modules.youtube_manager import get_ytmetas
6
 
7
 
@@ -21,6 +22,7 @@ def on_change_models(model_size):
21
 
22
 
23
  whisper_inf = WhisperInference()
 
24
  block = gr.Blocks(css=CSS).queue(api_open=False)
25
 
26
  with block:
@@ -100,4 +102,29 @@ with block:
100
  btn_openfolder.click(fn=lambda: open_fodler("outputs"), inputs=None, outputs=None)
101
  dd_model.change(fn=on_change_models, inputs=[dd_model], outputs=[cb_translate])
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  block.launch()
 
1
  import gradio as gr
2
  from modules.whisper_Inference import WhisperInference
3
+ from modules.nllb_inference import NLLBInference
4
  import os
5
+ from ui.htmls import *
6
  from modules.youtube_manager import get_ytmetas
7
 
8
 
 
22
 
23
 
24
  whisper_inf = WhisperInference()
25
+ nllb_inf = NLLBInference()
26
  block = gr.Blocks(css=CSS).queue(api_open=False)
27
 
28
  with block:
 
102
  btn_openfolder.click(fn=lambda: open_fodler("outputs"), inputs=None, outputs=None)
103
  dd_model.change(fn=on_change_models, inputs=[dd_model], outputs=[cb_translate])
104
 
105
+ with gr.TabItem("T2T Translation"): # tab 4
106
+ with gr.Row():
107
+ file_subs = gr.Files(type="file", label="Upload Subtitle Files to translate here",
108
+ file_types=['.vtt', '.srt'])
109
+
110
+ with gr.TabItem("NLLB"): # sub tab1
111
+ with gr.Row():
112
+ dd_nllb_model = gr.Dropdown(label="Model", value=nllb_inf.default_model_size,
113
+ choices=nllb_inf.available_models)
114
+ dd_nllb_sourcelang = gr.Dropdown(label="Source Language", choices=nllb_inf.available_source_langs)
115
+ dd_nllb_targetlang = gr.Dropdown(label="Target Language", choices=nllb_inf.available_target_langs)
116
+ with gr.Row():
117
+ btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
118
+ with gr.Row():
119
+ tb_indicator = gr.Textbox(label="Output")
120
+ btn_openfolder = gr.Button('πŸ“‚').style(full_width=False)
121
+ with gr.Column():
122
+ md_vram_table = gr.HTML(NLLB_VRAM_TABLE, elem_id="md_nllb_vram_table")
123
+
124
+ btn_run.click(fn=nllb_inf.translate_file,
125
+ inputs=[file_subs, dd_nllb_model, dd_nllb_sourcelang, dd_nllb_targetlang],
126
+ outputs=[tb_indicator])
127
+ btn_openfolder.click(fn=lambda: open_fodler("outputs\\translations"), inputs=None, outputs=None)
128
+
129
+
130
  block.launch()
modules/nllb_inference.py CHANGED
@@ -68,7 +68,7 @@ class NLLBInference:
68
 
69
  write_file(subtitle, f"{output_path}.srt")
70
 
71
- elif file_path == ".vtt":
72
  parsed_dicts = parse_vtt(file_path=file_path)
73
  total_progress = len(parsed_dicts)
74
  for index, dic in enumerate(parsed_dicts):
 
68
 
69
  write_file(subtitle, f"{output_path}.srt")
70
 
71
+ elif file_ext == ".vtt":
72
  parsed_dicts = parse_vtt(file_path=file_path)
73
  total_progress = len(parsed_dicts)
74
  for index, dic in enumerate(parsed_dicts):
outputs/translations/outputs for translation are saved here.txt ADDED
File without changes
ui/htmls.py CHANGED
@@ -39,4 +39,59 @@ CSS = """
39
 
40
  MARKDOWN = """
41
  ### [Whisper Web-UI](https://github.com/jhj0517/Whsiper-WebUI)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  """
 
39
 
40
  MARKDOWN = """
41
  ### [Whisper Web-UI](https://github.com/jhj0517/Whsiper-WebUI)
42
+ """
43
+
44
+
45
+ NLLB_VRAM_TABLE = """
46
+ <!DOCTYPE html>
47
+ <html lang="en">
48
+ <head>
49
+ <meta charset="UTF-8">
50
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
51
+ <style>
52
+ table {
53
+ border-collapse: collapse;
54
+ width: 100%;
55
+ }
56
+ th, td {
57
+ border: 1px solid #dddddd;
58
+ text-align: left;
59
+ padding: 8px;
60
+ }
61
+ th {
62
+ background-color: #f2f2f2;
63
+ }
64
+ </style>
65
+ </head>
66
+ <body>
67
+
68
+ <details>
69
+ <summary>VRAM usage for each model</summary>
70
+ <table>
71
+ <thead>
72
+ <tr>
73
+ <th>Model name</th>
74
+ <th>Required VRAM</th>
75
+ </tr>
76
+ </thead>
77
+ <tbody>
78
+ <tr>
79
+ <td>nllb-200-3.3B</td>
80
+ <td>~16GB</td>
81
+ </tr>
82
+ <tr>
83
+ <td>nllb-200-1.3B</td>
84
+ <td>~8GB</td>
85
+ </tr>
86
+ <tr>
87
+ <td>nllb-200-distilled-600M</td>
88
+ <td>~4GB</td>
89
+ </tr>
90
+ </tbody>
91
+ </table>
92
+ <p><strong>Note:</strong> Be mindful of your VRAM! The table above provides an approximate VRAM usage for each model.</p>
93
+ </details>
94
+
95
+ </body>
96
+ </html>
97
  """