Add all folders before coding
Browse files
app.py
CHANGED
|
@@ -15,12 +15,12 @@ NUMBER = 100
|
|
| 15 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 16 |
# DEVICE = "cpu"
|
| 17 |
DOWNLOAD = True
|
| 18 |
-
SLICE_AUDIO =
|
| 19 |
SEPARE_VOCALS = False
|
| 20 |
-
TRANSCRIBE_AUDIO =
|
| 21 |
-
CONCATENATE_TRANSCRIPTIONS =
|
| 22 |
-
TRANSLATE_TRANSCRIPTIONS =
|
| 23 |
-
ADD_SUBTITLES_TO_VIDEO =
|
| 24 |
REMOVE_FILES = False
|
| 25 |
if SEPARE_VOCALS:
|
| 26 |
SECONDS = 150
|
|
@@ -36,6 +36,18 @@ language_dict = union_language_dict()
|
|
| 36 |
def subtify_no_ui():
|
| 37 |
number_works = 7
|
| 38 |
progress_bar = tqdm(total=number_works, desc="Subtify")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
################## Download video and audio ##################
|
| 41 |
if DOWNLOAD:
|
|
@@ -83,8 +95,6 @@ def subtify_no_ui():
|
|
| 83 |
os.system(command)
|
| 84 |
else:
|
| 85 |
print("Moving chunks")
|
| 86 |
-
folder_vocals = "vocals"
|
| 87 |
-
folder_chunck = "chunks"
|
| 88 |
with open(f"{folder_vocals}/speakers.txt", 'w') as f:
|
| 89 |
f.write(str(0))
|
| 90 |
if REMOVE_FILES:
|
|
@@ -339,10 +349,13 @@ def get_audio_and_video_from_video(url, stream_page):
|
|
| 339 |
def trascribe_audio(audio_path, source_languaje):
|
| 340 |
folder_vocals = "vocals"
|
| 341 |
folder_chunck = "chunks"
|
|
|
|
| 342 |
if not os.path.exists(folder_vocals):
|
| 343 |
os.makedirs(folder_vocals)
|
| 344 |
if not os.path.exists(folder_chunck):
|
| 345 |
os.makedirs(folder_chunck)
|
|
|
|
|
|
|
| 346 |
python_file = "slice_audio.py"
|
| 347 |
command = f"python {python_file} {audio_path} {SECONDS}"
|
| 348 |
os.system(command)
|
|
@@ -402,6 +415,9 @@ def trascribe_audio(audio_path, source_languaje):
|
|
| 402 |
)
|
| 403 |
|
| 404 |
def translate_transcription(original_audio_transcribed_path, source_languaje, target_languaje):
|
|
|
|
|
|
|
|
|
|
| 405 |
python_file = "translate_transcriptions.py"
|
| 406 |
command = f"python {python_file} {original_audio_transcribed_path} --source_languaje {source_languaje} --target_languaje {target_languaje} --device {DEVICE}"
|
| 407 |
os.system(command)
|
|
@@ -442,7 +458,7 @@ def subtify():
|
|
| 442 |
with gr.Blocks() as demo:
|
| 443 |
# Layout
|
| 444 |
gr.Markdown("""# Subtify""")
|
| 445 |
-
gr.Markdown("transcribe, Python: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
|
| 446 |
# model = transformers.AutoModel.from_pretrained("huggingface/my_model")
|
| 447 |
# gr.Markdown(f"model.config.url: {model.config.url}")
|
| 448 |
token = os.getenv("HF_TOKEN")
|
|
|
|
| 15 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 16 |
# DEVICE = "cpu"
|
| 17 |
DOWNLOAD = True
|
| 18 |
+
SLICE_AUDIO = True
|
| 19 |
SEPARE_VOCALS = False
|
| 20 |
+
TRANSCRIBE_AUDIO = True
|
| 21 |
+
CONCATENATE_TRANSCRIPTIONS = True
|
| 22 |
+
TRANSLATE_TRANSCRIPTIONS = True
|
| 23 |
+
ADD_SUBTITLES_TO_VIDEO = True
|
| 24 |
REMOVE_FILES = False
|
| 25 |
if SEPARE_VOCALS:
|
| 26 |
SECONDS = 150
|
|
|
|
| 36 |
def subtify_no_ui():
|
| 37 |
number_works = 7
|
| 38 |
progress_bar = tqdm(total=number_works, desc="Subtify")
|
| 39 |
+
folder_vocals = "vocals"
|
| 40 |
+
folder_chunck = "chunks"
|
| 41 |
+
folder_concatenated = "concatenated_transcriptions"
|
| 42 |
+
folder_translated_transcriptions = "translated_transcriptions"
|
| 43 |
+
if not os.path.exists(folder_vocals):
|
| 44 |
+
os.makedirs(folder_vocals)
|
| 45 |
+
if not os.path.exists(folder_chunck):
|
| 46 |
+
os.makedirs(folder_chunck)
|
| 47 |
+
if not os.path.exists(folder_concatenated):
|
| 48 |
+
os.makedirs(folder_concatenated)
|
| 49 |
+
if not os.path.exists(folder_translated_transcriptions):
|
| 50 |
+
os.makedirs(folder_translated_transcriptions)
|
| 51 |
|
| 52 |
################## Download video and audio ##################
|
| 53 |
if DOWNLOAD:
|
|
|
|
| 95 |
os.system(command)
|
| 96 |
else:
|
| 97 |
print("Moving chunks")
|
|
|
|
|
|
|
| 98 |
with open(f"{folder_vocals}/speakers.txt", 'w') as f:
|
| 99 |
f.write(str(0))
|
| 100 |
if REMOVE_FILES:
|
|
|
|
| 349 |
def trascribe_audio(audio_path, source_languaje):
|
| 350 |
folder_vocals = "vocals"
|
| 351 |
folder_chunck = "chunks"
|
| 352 |
+
folder_concatenated = "concatenated_transcriptions"
|
| 353 |
if not os.path.exists(folder_vocals):
|
| 354 |
os.makedirs(folder_vocals)
|
| 355 |
if not os.path.exists(folder_chunck):
|
| 356 |
os.makedirs(folder_chunck)
|
| 357 |
+
if not os.path.exists(folder_concatenated):
|
| 358 |
+
os.makedirs(folder_concatenated)
|
| 359 |
python_file = "slice_audio.py"
|
| 360 |
command = f"python {python_file} {audio_path} {SECONDS}"
|
| 361 |
os.system(command)
|
|
|
|
| 415 |
)
|
| 416 |
|
| 417 |
def translate_transcription(original_audio_transcribed_path, source_languaje, target_languaje):
|
| 418 |
+
folder_translated_transcriptions = "translated_transcriptions"
|
| 419 |
+
if not os.path.exists(folder_translated_transcriptions):
|
| 420 |
+
os.makedirs(folder_translated_transcriptions)
|
| 421 |
python_file = "translate_transcriptions.py"
|
| 422 |
command = f"python {python_file} {original_audio_transcribed_path} --source_languaje {source_languaje} --target_languaje {target_languaje} --device {DEVICE}"
|
| 423 |
os.system(command)
|
|
|
|
| 458 |
with gr.Blocks() as demo:
|
| 459 |
# Layout
|
| 460 |
gr.Markdown("""# Subtify""")
|
| 461 |
+
gr.Markdown(f"transcribe, Python: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
|
| 462 |
# model = transformers.AutoModel.from_pretrained("huggingface/my_model")
|
| 463 |
# gr.Markdown(f"model.config.url: {model.config.url}")
|
| 464 |
token = os.getenv("HF_TOKEN")
|