Spaces:
Running
Running
jhj0517
commited on
Commit
·
d36cf56
1
Parent(s):
5c966f8
Fix file name and add `add_timestamp` parameter
Browse files- app.py +4 -1
- modules/translation/deepl_api.py +12 -6
app.py
CHANGED
@@ -257,6 +257,9 @@ class App:
|
|
257 |
self.deepl_api.available_target_langs.keys()))
|
258 |
with gr.Row():
|
259 |
cb_deepl_ispro = gr.Checkbox(label="Pro User?", value=False)
|
|
|
|
|
|
|
260 |
with gr.Row():
|
261 |
btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
|
262 |
with gr.Row():
|
@@ -266,7 +269,7 @@ class App:
|
|
266 |
|
267 |
btn_run.click(fn=self.deepl_api.translate_deepl,
|
268 |
inputs=[tb_authkey, file_subs, dd_deepl_sourcelang, dd_deepl_targetlang,
|
269 |
-
cb_deepl_ispro],
|
270 |
outputs=[tb_indicator, files_subtitles])
|
271 |
|
272 |
btn_openfolder.click(fn=lambda: self.open_folder(os.path.join("outputs", "translations")),
|
|
|
257 |
self.deepl_api.available_target_langs.keys()))
|
258 |
with gr.Row():
|
259 |
cb_deepl_ispro = gr.Checkbox(label="Pro User?", value=False)
|
260 |
+
with gr.Row():
|
261 |
+
cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename",
|
262 |
+
interactive=True)
|
263 |
with gr.Row():
|
264 |
btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
|
265 |
with gr.Row():
|
|
|
269 |
|
270 |
btn_run.click(fn=self.deepl_api.translate_deepl,
|
271 |
inputs=[tb_authkey, file_subs, dd_deepl_sourcelang, dd_deepl_targetlang,
|
272 |
+
cb_deepl_ispro, cb_timestamp],
|
273 |
outputs=[tb_indicator, files_subtitles])
|
274 |
|
275 |
btn_openfolder.click(fn=lambda: self.open_folder(os.path.join("outputs", "translations")),
|
modules/translation/deepl_api.py
CHANGED
@@ -97,6 +97,7 @@ class DeepLAPI:
|
|
97 |
source_lang: str,
|
98 |
target_lang: str,
|
99 |
is_pro: bool,
|
|
|
100 |
progress=gr.Progress()) -> list:
|
101 |
"""
|
102 |
Translate subtitle files using DeepL API
|
@@ -112,6 +113,8 @@ class DeepLAPI:
|
|
112 |
Target language of the file to transcribe from gr.Dropdown()
|
113 |
is_pro: str
|
114 |
Boolean value that is about pro user or not from gr.Checkbox().
|
|
|
|
|
115 |
progress: gr.Progress
|
116 |
Indicator to show progress directly in gradio.
|
117 |
|
@@ -141,10 +144,12 @@ class DeepLAPI:
|
|
141 |
progress(batch_end / len(parsed_dicts), desc="Translating..")
|
142 |
|
143 |
subtitle = get_serialized_srt(parsed_dicts)
|
144 |
-
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
145 |
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
148 |
write_file(subtitle, output_path)
|
149 |
|
150 |
elif file_ext == ".vtt":
|
@@ -161,11 +166,12 @@ class DeepLAPI:
|
|
161 |
progress(batch_end / len(parsed_dicts), desc="Translating..")
|
162 |
|
163 |
subtitle = get_serialized_vtt(parsed_dicts)
|
164 |
-
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
165 |
|
166 |
-
|
167 |
-
|
|
|
168 |
|
|
|
169 |
write_file(subtitle, output_path)
|
170 |
|
171 |
files_info[file_name] = {"subtitle": subtitle, "path": output_path}
|
|
|
97 |
source_lang: str,
|
98 |
target_lang: str,
|
99 |
is_pro: bool,
|
100 |
+
add_timestamp: bool,
|
101 |
progress=gr.Progress()) -> list:
|
102 |
"""
|
103 |
Translate subtitle files using DeepL API
|
|
|
113 |
Target language of the file to transcribe from gr.Dropdown()
|
114 |
is_pro: str
|
115 |
Boolean value that is about pro user or not from gr.Checkbox().
|
116 |
+
add_timestamp: bool
|
117 |
+
Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the filename.
|
118 |
progress: gr.Progress
|
119 |
Indicator to show progress directly in gradio.
|
120 |
|
|
|
144 |
progress(batch_end / len(parsed_dicts), desc="Translating..")
|
145 |
|
146 |
subtitle = get_serialized_srt(parsed_dicts)
|
|
|
147 |
|
148 |
+
if add_timestamp:
|
149 |
+
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
150 |
+
file_name += f"-{timestamp}"
|
151 |
+
|
152 |
+
output_path = os.path.join(self.output_dir, "", f"{file_name}.srt")
|
153 |
write_file(subtitle, output_path)
|
154 |
|
155 |
elif file_ext == ".vtt":
|
|
|
166 |
progress(batch_end / len(parsed_dicts), desc="Translating..")
|
167 |
|
168 |
subtitle = get_serialized_vtt(parsed_dicts)
|
|
|
169 |
|
170 |
+
if add_timestamp:
|
171 |
+
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
172 |
+
file_name += f"-{timestamp}"
|
173 |
|
174 |
+
output_path = os.path.join(self.output_dir, "", f"{file_name}.vtt")
|
175 |
write_file(subtitle, output_path)
|
176 |
|
177 |
files_info[file_name] = {"subtitle": subtitle, "path": output_path}
|