Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ from modules.youtube_manager import get_ytmetas
|
|
| 10 |
from modules.deepl_api import DeepLAPI
|
| 11 |
from modules.whisper_parameter import *
|
| 12 |
|
|
|
|
| 13 |
# Ensure the outputs directory exists
|
| 14 |
def ensure_output_directory():
|
| 15 |
output_directories = ["outputs", "outputs/translations"]
|
|
@@ -17,6 +18,7 @@ def ensure_output_directory():
|
|
| 17 |
if not os.path.exists(directory):
|
| 18 |
os.makedirs(directory)
|
| 19 |
|
|
|
|
| 20 |
class App:
|
| 21 |
def __init__(self, args):
|
| 22 |
ensure_output_directory() # Making sure the output directories exist
|
|
@@ -34,10 +36,11 @@ class App:
|
|
| 34 |
if whisper_type in ["faster_whisper", "faster-whisper"]:
|
| 35 |
whisper_inf = FasterWhisperInference()
|
| 36 |
whisper_inf.model_dir = self.args.faster_whisper_model_dir
|
| 37 |
-
|
| 38 |
whisper_inf = WhisperInference()
|
| 39 |
whisper_inf.model_dir = self.args.whisper_model_dir
|
| 40 |
else:
|
|
|
|
| 41 |
whisper_inf = FasterWhisperInference()
|
| 42 |
whisper_inf.model_dir = self.args.faster_whisper_model_dir
|
| 43 |
return whisper_inf
|
|
@@ -140,16 +143,14 @@ class App:
|
|
| 140 |
tb_title = gr.Label(label="Youtube Title")
|
| 141 |
tb_description = gr.Textbox(label="Youtube Description", max_lines=15)
|
| 142 |
with gr.Row():
|
| 143 |
-
dd_model = gr.Dropdown(choices=self.whisper_inf.available_models, value="large-v2",
|
| 144 |
-
label="Model")
|
| 145 |
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + self.whisper_inf.available_langs,
|
| 146 |
value="Automatic Detection", label="Language")
|
| 147 |
dd_file_format = gr.Dropdown(choices=["SRT", "WebVTT", "txt"], value="SRT", label="File Format")
|
| 148 |
with gr.Row():
|
| 149 |
cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
|
| 150 |
with gr.Row():
|
| 151 |
-
cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename",
|
| 152 |
-
interactive=True)
|
| 153 |
with gr.Accordion("VAD Options", open=False, visible=isinstance(self.whisper_inf, FasterWhisperInference)):
|
| 154 |
cb_vad_filter = gr.Checkbox(label="Enable Silero VAD Filter", value=False, interactive=True)
|
| 155 |
sd_threshold = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="Speech Threshold", value=0.5)
|
|
@@ -197,6 +198,7 @@ class App:
|
|
| 197 |
min_silence_duration_ms=nb_min_silence_duration_ms,
|
| 198 |
window_size_sample=nb_window_size_sample,
|
| 199 |
speech_pad_ms=nb_speech_pad_ms)
|
|
|
|
| 200 |
btn_run.click(fn=self.whisper_inf.transcribe_youtube,
|
| 201 |
inputs=params + whisper_params.to_list(),
|
| 202 |
outputs=[tb_indicator, files_subtitles])
|
|
@@ -262,6 +264,7 @@ class App:
|
|
| 262 |
min_silence_duration_ms=nb_min_silence_duration_ms,
|
| 263 |
window_size_sample=nb_window_size_sample,
|
| 264 |
speech_pad_ms=nb_speech_pad_ms)
|
|
|
|
| 265 |
btn_run.click(fn=self.whisper_inf.transcribe_mic,
|
| 266 |
inputs=params + whisper_params.to_list(),
|
| 267 |
outputs=[tb_indicator, files_subtitles])
|
|
@@ -275,15 +278,12 @@ class App:
|
|
| 275 |
|
| 276 |
with gr.TabItem("DeepL API"): # sub tab1
|
| 277 |
with gr.Row():
|
| 278 |
-
tb_authkey = gr.Textbox(label="Your Auth Key (API KEY)",
|
| 279 |
-
value="")
|
| 280 |
with gr.Row():
|
| 281 |
dd_deepl_sourcelang = gr.Dropdown(label="Source Language", value="Automatic Detection",
|
| 282 |
-
choices=list(
|
| 283 |
-
self.deepl_api.available_source_langs.keys()))
|
| 284 |
dd_deepl_targetlang = gr.Dropdown(label="Target Language", value="English",
|
| 285 |
-
choices=list(
|
| 286 |
-
self.deepl_api.available_target_langs.keys()))
|
| 287 |
with gr.Row():
|
| 288 |
cb_deepl_ispro = gr.Checkbox(label="Pro User?", value=False)
|
| 289 |
with gr.Row():
|
|
@@ -294,13 +294,11 @@ class App:
|
|
| 294 |
btn_openfolder = gr.Button('📂', scale=1)
|
| 295 |
|
| 296 |
btn_run.click(fn=self.deepl_api.translate_deepl,
|
| 297 |
-
inputs=[tb_authkey, file_subs, dd_deepl_sourcelang, dd_deepl_targetlang,
|
| 298 |
-
cb_deepl_ispro],
|
| 299 |
outputs=[tb_indicator, files_subtitles])
|
| 300 |
|
| 301 |
btn_openfolder.click(fn=lambda: self.open_folder(os.path.join("outputs", "translations")),
|
| 302 |
-
inputs=None,
|
| 303 |
-
outputs=None)
|
| 304 |
|
| 305 |
with gr.TabItem("NLLB"): # sub tab2
|
| 306 |
with gr.Row():
|
|
@@ -308,11 +306,9 @@ class App:
|
|
| 308 |
choices=self.nllb_inf.available_models)
|
| 309 |
dd_nllb_sourcelang = gr.Dropdown(label="Source Language",
|
| 310 |
choices=self.nllb_inf.available_source_langs)
|
| 311 |
-
dd_nllb_targetlang = gr.Dropdown(label="Target Language",
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename",
|
| 315 |
-
interactive=True)
|
| 316 |
with gr.Row():
|
| 317 |
btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
|
| 318 |
with gr.Row():
|
|
@@ -327,8 +323,7 @@ class App:
|
|
| 327 |
outputs=[tb_indicator, files_subtitles])
|
| 328 |
|
| 329 |
btn_openfolder.click(fn=lambda: self.open_folder(os.path.join("outputs", "translations")),
|
| 330 |
-
inputs=None,
|
| 331 |
-
outputs=None)
|
| 332 |
|
| 333 |
# Launch the app with optional gradio settings
|
| 334 |
launch_args = {}
|
|
|
|
| 10 |
from modules.deepl_api import DeepLAPI
|
| 11 |
from modules.whisper_parameter import *
|
| 12 |
|
| 13 |
+
|
| 14 |
# Ensure the outputs directory exists
|
| 15 |
def ensure_output_directory():
|
| 16 |
output_directories = ["outputs", "outputs/translations"]
|
|
|
|
| 18 |
if not os.path.exists(directory):
|
| 19 |
os.makedirs(directory)
|
| 20 |
|
| 21 |
+
|
| 22 |
class App:
|
| 23 |
def __init__(self, args):
|
| 24 |
ensure_output_directory() # Making sure the output directories exist
|
|
|
|
| 36 |
if whisper_type in ["faster_whisper", "faster-whisper"]:
|
| 37 |
whisper_inf = FasterWhisperInference()
|
| 38 |
whisper_inf.model_dir = self.args.faster_whisper_model_dir
|
| 39 |
+
elif whisper_type == "whisper":
|
| 40 |
whisper_inf = WhisperInference()
|
| 41 |
whisper_inf.model_dir = self.args.whisper_model_dir
|
| 42 |
else:
|
| 43 |
+
# Default to FasterWhisperInference
|
| 44 |
whisper_inf = FasterWhisperInference()
|
| 45 |
whisper_inf.model_dir = self.args.faster_whisper_model_dir
|
| 46 |
return whisper_inf
|
|
|
|
| 143 |
tb_title = gr.Label(label="Youtube Title")
|
| 144 |
tb_description = gr.Textbox(label="Youtube Description", max_lines=15)
|
| 145 |
with gr.Row():
|
| 146 |
+
dd_model = gr.Dropdown(choices=self.whisper_inf.available_models, value="large-v2", label="Model")
|
|
|
|
| 147 |
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + self.whisper_inf.available_langs,
|
| 148 |
value="Automatic Detection", label="Language")
|
| 149 |
dd_file_format = gr.Dropdown(choices=["SRT", "WebVTT", "txt"], value="SRT", label="File Format")
|
| 150 |
with gr.Row():
|
| 151 |
cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
|
| 152 |
with gr.Row():
|
| 153 |
+
cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename", interactive=True)
|
|
|
|
| 154 |
with gr.Accordion("VAD Options", open=False, visible=isinstance(self.whisper_inf, FasterWhisperInference)):
|
| 155 |
cb_vad_filter = gr.Checkbox(label="Enable Silero VAD Filter", value=False, interactive=True)
|
| 156 |
sd_threshold = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="Speech Threshold", value=0.5)
|
|
|
|
| 198 |
min_silence_duration_ms=nb_min_silence_duration_ms,
|
| 199 |
window_size_sample=nb_window_size_sample,
|
| 200 |
speech_pad_ms=nb_speech_pad_ms)
|
| 201 |
+
|
| 202 |
btn_run.click(fn=self.whisper_inf.transcribe_youtube,
|
| 203 |
inputs=params + whisper_params.to_list(),
|
| 204 |
outputs=[tb_indicator, files_subtitles])
|
|
|
|
| 264 |
min_silence_duration_ms=nb_min_silence_duration_ms,
|
| 265 |
window_size_sample=nb_window_size_sample,
|
| 266 |
speech_pad_ms=nb_speech_pad_ms)
|
| 267 |
+
|
| 268 |
btn_run.click(fn=self.whisper_inf.transcribe_mic,
|
| 269 |
inputs=params + whisper_params.to_list(),
|
| 270 |
outputs=[tb_indicator, files_subtitles])
|
|
|
|
| 278 |
|
| 279 |
with gr.TabItem("DeepL API"): # sub tab1
|
| 280 |
with gr.Row():
|
| 281 |
+
tb_authkey = gr.Textbox(label="Your Auth Key (API KEY)", value="")
|
|
|
|
| 282 |
with gr.Row():
|
| 283 |
dd_deepl_sourcelang = gr.Dropdown(label="Source Language", value="Automatic Detection",
|
| 284 |
+
choices=list(self.deepl_api.available_source_langs.keys()))
|
|
|
|
| 285 |
dd_deepl_targetlang = gr.Dropdown(label="Target Language", value="English",
|
| 286 |
+
choices=list(self.deepl_api.available_target_langs.keys()))
|
|
|
|
| 287 |
with gr.Row():
|
| 288 |
cb_deepl_ispro = gr.Checkbox(label="Pro User?", value=False)
|
| 289 |
with gr.Row():
|
|
|
|
| 294 |
btn_openfolder = gr.Button('📂', scale=1)
|
| 295 |
|
| 296 |
btn_run.click(fn=self.deepl_api.translate_deepl,
|
| 297 |
+
inputs=[tb_authkey, file_subs, dd_deepl_sourcelang, dd_deepl_targetlang, cb_deepl_ispro],
|
|
|
|
| 298 |
outputs=[tb_indicator, files_subtitles])
|
| 299 |
|
| 300 |
btn_openfolder.click(fn=lambda: self.open_folder(os.path.join("outputs", "translations")),
|
| 301 |
+
inputs=None, outputs=None)
|
|
|
|
| 302 |
|
| 303 |
with gr.TabItem("NLLB"): # sub tab2
|
| 304 |
with gr.Row():
|
|
|
|
| 306 |
choices=self.nllb_inf.available_models)
|
| 307 |
dd_nllb_sourcelang = gr.Dropdown(label="Source Language",
|
| 308 |
choices=self.nllb_inf.available_source_langs)
|
| 309 |
+
dd_nllb_targetlang = gr.Dropdown(label="Target Language", choices=self.nllb_inf.available_target_langs)
|
| 310 |
+
with gr.Row():
|
| 311 |
+
cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename", interactive=True)
|
|
|
|
|
|
|
| 312 |
with gr.Row():
|
| 313 |
btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
|
| 314 |
with gr.Row():
|
|
|
|
| 323 |
outputs=[tb_indicator, files_subtitles])
|
| 324 |
|
| 325 |
btn_openfolder.click(fn=lambda: self.open_folder(os.path.join("outputs", "translations")),
|
| 326 |
+
inputs=None, outputs=None)
|
|
|
|
| 327 |
|
| 328 |
# Launch the app with optional gradio settings
|
| 329 |
launch_args = {}
|