Maximofn commited on
Commit
c5eae48
1 Parent(s): e0d1084

Check if files exits before delete there

Browse files
Files changed (1) hide show
  1. app.py +59 -37
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
- command = f"rm {transcription_file}"
275
- os.system(command)
 
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
- command = f"rm {input_video_file}"
292
- os.system(command)
293
- command = f"rm {input_audio_file}"
294
- os.system(command)
295
- command = f"rm {transcription_file}"
296
- os.system(command)
297
- command = f"rm chunks/output_files.txt"
298
- os.system(command)
299
- command = f"rm vocals/speakers.txt"
300
- os.system(command)
 
 
 
 
 
 
 
 
301
  print('*'*NUMBER)
302
  print("\n\n")
303
  progress_bar.update(1)
304
 
305
  def remove_all_files():
306
- command = f"rm -r audios"
307
- os.system(command)
308
- command = f"rm -r chunks"
309
- os.system(command)
310
- command = f"rm -r concatenated_transcriptions"
311
- os.system(command)
312
- command = f"rm -r transcriptions"
313
- os.system(command)
314
- command = f"rm -r translated_transcriptions"
315
- os.system(command)
316
- command = f"rm -r videos"
317
- os.system(command)
318
- command = f"rm -r vocals"
319
- os.system(command)
 
 
 
 
 
 
 
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
- command = f"rm {transcription_file}"
544
- os.system(command)
 
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
- command = f"rm {original_video_path}"
557
- os.system(command)
558
- command = f"rm {original_audio_path}"
559
- os.system(command)
560
- command = f"rm {original_audio_translated_path}"
561
- os.system(command)
562
- command = f"rm chunks/output_files.txt"
563
- os.system(command)
 
 
 
 
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