Spaces:
Running
Running
jhj0517
commited on
Commit
β’
eef1e47
1
Parent(s):
6222690
add deepl api tab
Browse files
app.py
CHANGED
@@ -7,19 +7,20 @@ from modules.faster_whisper_inference import FasterWhisperInference
|
|
7 |
from modules.nllb_inference import NLLBInference
|
8 |
from ui.htmls import *
|
9 |
from modules.youtube_manager import get_ytmetas
|
10 |
-
|
11 |
|
12 |
class App:
|
13 |
def __init__(self, args):
|
14 |
self.args = args
|
15 |
self.app = gr.Blocks(css=CSS, theme=self.args.theme)
|
16 |
-
self.whisper_inf = WhisperInference() if self.args.disable_faster_whisper else FasterWhisperInference()
|
17 |
if isinstance(self.whisper_inf, FasterWhisperInference):
|
18 |
print("Use Faster Whisper implementation")
|
19 |
else:
|
20 |
print("Use Open AI Whisper implementation")
|
21 |
print(f"Device \"{self.whisper_inf.device}\" is detected")
|
22 |
self.nllb_inf = NLLBInference()
|
|
|
23 |
|
24 |
@staticmethod
|
25 |
def open_folder(folder_path: str):
|
@@ -153,7 +154,36 @@ class App:
|
|
153 |
file_subs = gr.Files(type="filepath", label="Upload Subtitle Files to translate here",
|
154 |
file_types=['.vtt', '.srt'])
|
155 |
|
156 |
-
with gr.TabItem("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
with gr.Row():
|
158 |
dd_nllb_model = gr.Dropdown(label="Model", value=self.nllb_inf.default_model_size,
|
159 |
choices=self.nllb_inf.available_models)
|
|
|
7 |
from modules.nllb_inference import NLLBInference
|
8 |
from ui.htmls import *
|
9 |
from modules.youtube_manager import get_ytmetas
|
10 |
+
from modules.deepl_api import DeepLAPI
|
11 |
|
12 |
class App:
|
13 |
def __init__(self, args):
|
14 |
self.args = args
|
15 |
self.app = gr.Blocks(css=CSS, theme=self.args.theme)
|
16 |
+
self.whisper_inf = WhisperInference() if self.args.disable_faster_whisper else FasterWhisperInference()
|
17 |
if isinstance(self.whisper_inf, FasterWhisperInference):
|
18 |
print("Use Faster Whisper implementation")
|
19 |
else:
|
20 |
print("Use Open AI Whisper implementation")
|
21 |
print(f"Device \"{self.whisper_inf.device}\" is detected")
|
22 |
self.nllb_inf = NLLBInference()
|
23 |
+
self.deepl_api = DeepLAPI()
|
24 |
|
25 |
@staticmethod
|
26 |
def open_folder(folder_path: str):
|
|
|
154 |
file_subs = gr.Files(type="filepath", label="Upload Subtitle Files to translate here",
|
155 |
file_types=['.vtt', '.srt'])
|
156 |
|
157 |
+
with gr.TabItem("DeepL API"): # sub tab1
|
158 |
+
with gr.Row():
|
159 |
+
tb_authkey = gr.Textbox(label="Your Auth Key (API KEY)",
|
160 |
+
value="")
|
161 |
+
with gr.Row():
|
162 |
+
dd_deepl_sourcelang = gr.Dropdown(label="Source Language", value="Automatic Detection",
|
163 |
+
choices=list(
|
164 |
+
self.deepl_api.available_source_langs.keys()))
|
165 |
+
dd_deepl_targetlang = gr.Dropdown(label="Target Language", value="English",
|
166 |
+
choices=list(
|
167 |
+
self.deepl_api.available_target_langs.keys()))
|
168 |
+
with gr.Row():
|
169 |
+
cb_deepl_ispro = gr.Checkbox(label="Pro User?", value=False)
|
170 |
+
with gr.Row():
|
171 |
+
btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
|
172 |
+
with gr.Row():
|
173 |
+
tb_indicator = gr.Textbox(label="Output", scale=4)
|
174 |
+
files_subtitles = gr.Files(label="Downloadable output file", scale=4)
|
175 |
+
btn_openfolder = gr.Button('π', scale=1)
|
176 |
+
|
177 |
+
btn_run.click(fn=self.deepl_api.translate_deepl,
|
178 |
+
inputs=[tb_authkey, file_subs, dd_deepl_sourcelang, dd_deepl_targetlang,
|
179 |
+
cb_deepl_ispro],
|
180 |
+
outputs=[tb_indicator, files_subtitles])
|
181 |
+
|
182 |
+
btn_openfolder.click(fn=lambda: self.open_folder(os.path.join("outputs", "translations")),
|
183 |
+
inputs=None,
|
184 |
+
outputs=None)
|
185 |
+
|
186 |
+
with gr.TabItem("NLLB"): # sub tab2
|
187 |
with gr.Row():
|
188 |
dd_nllb_model = gr.Dropdown(label="Model", value=self.nllb_inf.default_model_size,
|
189 |
choices=self.nllb_inf.available_models)
|