Check if files exits before delete there
Browse files
app.py
CHANGED
|
@@ -181,11 +181,12 @@ def subtify_no_ui():
|
|
| 181 |
if DOWNLOAD:
|
| 182 |
print('*'*NUMBER)
|
| 183 |
# url = "https://www.twitch.tv/videos/1936119752" # twitch Rob Mula 2 horas
|
| 184 |
-
url = "https://www.youtube.com/watch?v=yX5EJf4R77s" # ✅ debate, varios hablantes, 3 minutos
|
| 185 |
# url = "https://www.youtube.com/watch?v=cgx0QnXo1OU" # ✅ smart home, un solo hablante, 4:42 minutos
|
| 186 |
# url = "https://www.youtube.com/watch?v=dgOBxhi19T8" # ✅ rob mula, muchos hablantes, 4:28 minutos
|
| 187 |
# url = "https://www.youtube.com/watch?v=Coj72EzmX20" # rob mula, un solo hablante, 16 minutos
|
| 188 |
# url = "https://www.youtube.com/watch?v=Tqth0fKo0_g" # Conversación short
|
|
|
|
| 189 |
print(f"Downloading video and audio from {url}")
|
| 190 |
python_file = "download.py"
|
| 191 |
command = f"python {python_file} {url}"
|
|
@@ -271,8 +272,9 @@ def subtify_no_ui():
|
|
| 271 |
command = f"python {python_file} {transcription_file} --source_languaje {source_languaje} --target_languaje {target_languaje} --device {DEVICE}"
|
| 272 |
os.system(command)
|
| 273 |
if REMOVE_FILES:
|
| 274 |
-
|
| 275 |
-
|
|
|
|
| 276 |
print('*'*NUMBER)
|
| 277 |
print("\n\n")
|
| 278 |
progress_bar.update(1)
|
|
@@ -288,35 +290,50 @@ def subtify_no_ui():
|
|
| 288 |
command = f"python {python_file} {transcription_file} {input_video_file} {input_audio_file}"
|
| 289 |
os.system(command)
|
| 290 |
if REMOVE_FILES:
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
os.
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
os.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
print('*'*NUMBER)
|
| 302 |
print("\n\n")
|
| 303 |
progress_bar.update(1)
|
| 304 |
|
| 305 |
def remove_all_files():
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
os.
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
os.
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
|
| 321 |
# def paste_url_from_clipboard():
|
| 322 |
# return pyperclip.paste()
|
|
@@ -540,8 +557,9 @@ def translate_transcription(original_audio_transcribed_path, source_languaje, ta
|
|
| 540 |
translated_transcription = f"translated_transcriptions/download_audio_{target_languaje}.srt"
|
| 541 |
|
| 542 |
transcription_file = "concatenated_transcriptions/download_audio.srt"
|
| 543 |
-
|
| 544 |
-
|
|
|
|
| 545 |
|
| 546 |
return (
|
| 547 |
gr.Textbox(value="Ok"),
|
|
@@ -553,14 +571,18 @@ def add_translated_subtitles_to_video(original_video_path, original_audio_path,
|
|
| 553 |
command = f"python {python_file} {original_audio_translated_path} {original_video_path} {original_audio_path}"
|
| 554 |
os.system(command)
|
| 555 |
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
os.
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 564 |
|
| 565 |
subtitled_video = "videos/download_video_with_subtitles.mp4"
|
| 566 |
|
|
|
|
| 181 |
if DOWNLOAD:
|
| 182 |
print('*'*NUMBER)
|
| 183 |
# url = "https://www.twitch.tv/videos/1936119752" # twitch Rob Mula 2 horas
|
| 184 |
+
# url = "https://www.youtube.com/watch?v=yX5EJf4R77s" # ✅ debate, varios hablantes, 3 minutos
|
| 185 |
# url = "https://www.youtube.com/watch?v=cgx0QnXo1OU" # ✅ smart home, un solo hablante, 4:42 minutos
|
| 186 |
# url = "https://www.youtube.com/watch?v=dgOBxhi19T8" # ✅ rob mula, muchos hablantes, 4:28 minutos
|
| 187 |
# url = "https://www.youtube.com/watch?v=Coj72EzmX20" # rob mula, un solo hablante, 16 minutos
|
| 188 |
# url = "https://www.youtube.com/watch?v=Tqth0fKo0_g" # Conversación short
|
| 189 |
+
url = "https://www.youtube.com/watch?v=h9xPrgTYP_0" # Letitia 40 segundos
|
| 190 |
print(f"Downloading video and audio from {url}")
|
| 191 |
python_file = "download.py"
|
| 192 |
command = f"python {python_file} {url}"
|
|
|
|
| 272 |
command = f"python {python_file} {transcription_file} --source_languaje {source_languaje} --target_languaje {target_languaje} --device {DEVICE}"
|
| 273 |
os.system(command)
|
| 274 |
if REMOVE_FILES:
|
| 275 |
+
if os.path.exists(transcription_file):
|
| 276 |
+
command = f"rm {transcription_file}"
|
| 277 |
+
os.system(command)
|
| 278 |
print('*'*NUMBER)
|
| 279 |
print("\n\n")
|
| 280 |
progress_bar.update(1)
|
|
|
|
| 290 |
command = f"python {python_file} {transcription_file} {input_video_file} {input_audio_file}"
|
| 291 |
os.system(command)
|
| 292 |
if REMOVE_FILES:
|
| 293 |
+
if os.path.exists(input_video_file):
|
| 294 |
+
command = f"rm {input_video_file}"
|
| 295 |
+
os.system(command)
|
| 296 |
+
if os.path.exists(input_audio_file):
|
| 297 |
+
command = f"rm {input_audio_file}"
|
| 298 |
+
os.system(command)
|
| 299 |
+
if os.path.exists(transcription_file):
|
| 300 |
+
command = f"rm {transcription_file}"
|
| 301 |
+
os.system(command)
|
| 302 |
+
if os.path.exists("chunks/output_files.txt"):
|
| 303 |
+
command = f"rm chunks/output_files.txt"
|
| 304 |
+
os.system(command)
|
| 305 |
+
if os.path.exists("chunks"):
|
| 306 |
+
command = f"rm -r chunks"
|
| 307 |
+
os.system(command)
|
| 308 |
+
if os.path.exists("vocals/speakers.txt"):
|
| 309 |
+
command = f"rm vocals/speakers.txt"
|
| 310 |
+
os.system(command)
|
| 311 |
print('*'*NUMBER)
|
| 312 |
print("\n\n")
|
| 313 |
progress_bar.update(1)
|
| 314 |
|
| 315 |
def remove_all_files():
|
| 316 |
+
if os.path.exists("audios"):
|
| 317 |
+
command = f"rm -r audios"
|
| 318 |
+
os.system(command)
|
| 319 |
+
if os.path.exists("chunks"):
|
| 320 |
+
command = f"rm -r chunks"
|
| 321 |
+
os.system(command)
|
| 322 |
+
if os.path.exists("concatenated_transcriptions"):
|
| 323 |
+
command = f"rm -r concatenated_transcriptions"
|
| 324 |
+
os.system(command)
|
| 325 |
+
if os.path.exists("transcriptions"):
|
| 326 |
+
command = f"rm -r transcriptions"
|
| 327 |
+
os.system(command)
|
| 328 |
+
if os.path.exists("translated_transcriptions"):
|
| 329 |
+
command = f"rm -r translated_transcriptions"
|
| 330 |
+
os.system(command)
|
| 331 |
+
if os.path.exists("videos"):
|
| 332 |
+
command = f"rm -r videos"
|
| 333 |
+
os.system(command)
|
| 334 |
+
if os.path.exists("vocals"):
|
| 335 |
+
command = f"rm -r vocals"
|
| 336 |
+
os.system(command)
|
| 337 |
|
| 338 |
# def paste_url_from_clipboard():
|
| 339 |
# return pyperclip.paste()
|
|
|
|
| 557 |
translated_transcription = f"translated_transcriptions/download_audio_{target_languaje}.srt"
|
| 558 |
|
| 559 |
transcription_file = "concatenated_transcriptions/download_audio.srt"
|
| 560 |
+
if os.path.exists(transcription_file):
|
| 561 |
+
command = f"rm {transcription_file}"
|
| 562 |
+
os.system(command)
|
| 563 |
|
| 564 |
return (
|
| 565 |
gr.Textbox(value="Ok"),
|
|
|
|
| 571 |
command = f"python {python_file} {original_audio_translated_path} {original_video_path} {original_audio_path}"
|
| 572 |
os.system(command)
|
| 573 |
|
| 574 |
+
if os.path.exists(original_video_path):
|
| 575 |
+
command = f"rm {original_video_path}"
|
| 576 |
+
os.system(command)
|
| 577 |
+
if os.path.exists(original_audio_path):
|
| 578 |
+
command = f"rm {original_audio_path}"
|
| 579 |
+
os.system(command)
|
| 580 |
+
if os.path.exists(original_audio_translated_path):
|
| 581 |
+
command = f"rm {original_audio_translated_path}"
|
| 582 |
+
os.system(command)
|
| 583 |
+
if os.path.exists("chunks/output_files.txt"):
|
| 584 |
+
command = f"rm chunks/output_files.txt"
|
| 585 |
+
os.system(command)
|
| 586 |
|
| 587 |
subtitled_video = "videos/download_video_with_subtitles.mp4"
|
| 588 |
|