Add delete buton
Browse files- app.py +79 -35
- assets/twitch.webp +0 -0
- assets/youtube-no-thumbnails.webp +0 -0
- assets/youtube_error.webp +0 -0
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import argparse
|
| 3 |
-
import sys
|
| 4 |
import os
|
| 5 |
import torch
|
| 6 |
from time import sleep
|
|
@@ -9,11 +8,9 @@ from lang_list import union_language_dict
|
|
| 9 |
# import pyperclip
|
| 10 |
from pytube import YouTube
|
| 11 |
import re
|
| 12 |
-
import transformers
|
| 13 |
|
| 14 |
NUMBER = 100
|
| 15 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 16 |
-
# DEVICE = "cpu"
|
| 17 |
DOWNLOAD = True
|
| 18 |
SLICE_AUDIO = True
|
| 19 |
SEPARE_VOCALS = False
|
|
@@ -228,23 +225,43 @@ def remove_all():
|
|
| 228 |
|
| 229 |
def clear_video_url():
|
| 230 |
visible = False
|
|
|
|
| 231 |
image = gr.Image(visible=visible, scale=1)
|
| 232 |
source_languaje = gr.Dropdown(visible=visible, label="Source languaje", show_label=True, value="English", choices=language_dict, scale=1, interactive=True)
|
| 233 |
target_languaje = gr.Dropdown(visible=visible, label="Target languaje", show_label=True, value="Español", choices=language_dict, scale=1, interactive=True)
|
| 234 |
-
num_speaker = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
|
| 235 |
number_of_speakers = gr.Dropdown(visible=visible, label="Number of speakers", show_label=True, value=10, choices=num_speaker, scale=1, interactive=True)
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
return (
|
| 240 |
"",
|
| 241 |
image,
|
| 242 |
source_languaje,
|
| 243 |
target_languaje,
|
| 244 |
number_of_speakers,
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
)
|
| 249 |
|
| 250 |
def get_youtube_thumbnail(url):
|
|
@@ -472,13 +489,14 @@ def add_translated_subtitles_to_video(original_video_path, original_audio_path,
|
|
| 472 |
|
| 473 |
def subtify():
|
| 474 |
with gr.Blocks() as demo:
|
| 475 |
-
# Layout
|
| 476 |
num_speaker = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
|
|
|
|
|
|
|
| 477 |
gr.Markdown("""# Subtify""")
|
| 478 |
with gr.Row(variant="panel"):
|
| 479 |
url_textbox = gr.Textbox(placeholder="Add video URL here", label="Video URL", elem_id="video_url", scale=1, interactive=True)
|
| 480 |
# copy_button = gr.Button(size="sm", icon="icons/copy.svg", value="", min_width="10px", scale=0)
|
| 481 |
-
|
| 482 |
|
| 483 |
visible = False
|
| 484 |
with gr.Row(equal_height=False):
|
|
@@ -508,37 +526,63 @@ def subtify():
|
|
| 508 |
|
| 509 |
# Events
|
| 510 |
# copy_button.click(fn=copy_url_from_clipboard, outputs=url_textbox)
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
# outputs=[
|
| 514 |
-
# url_textbox,
|
| 515 |
-
# image,
|
| 516 |
-
# source_languaje,
|
| 517 |
-
# target_languaje,
|
| 518 |
-
# number_of_speakers,
|
| 519 |
-
# subtify_button,
|
| 520 |
-
# original_audio_transcribed,
|
| 521 |
-
# original_audio_translated,
|
| 522 |
-
# ]
|
| 523 |
-
# )
|
| 524 |
-
url_textbox.change(
|
| 525 |
-
fn=is_valid_url,
|
| 526 |
-
inputs=url_textbox,
|
| 527 |
outputs=[
|
|
|
|
| 528 |
image,
|
| 529 |
source_languaje,
|
| 530 |
target_languaje,
|
| 531 |
number_of_speakers,
|
| 532 |
subtify_button,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
]
|
| 534 |
)
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 542 |
|
| 543 |
demo.launch()
|
| 544 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import argparse
|
|
|
|
| 3 |
import os
|
| 4 |
import torch
|
| 5 |
from time import sleep
|
|
|
|
| 8 |
# import pyperclip
|
| 9 |
from pytube import YouTube
|
| 10 |
import re
|
|
|
|
| 11 |
|
| 12 |
NUMBER = 100
|
| 13 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 14 |
DOWNLOAD = True
|
| 15 |
SLICE_AUDIO = True
|
| 16 |
SEPARE_VOCALS = False
|
|
|
|
| 225 |
|
| 226 |
def clear_video_url():
|
| 227 |
visible = False
|
| 228 |
+
num_speaker = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
|
| 229 |
image = gr.Image(visible=visible, scale=1)
|
| 230 |
source_languaje = gr.Dropdown(visible=visible, label="Source languaje", show_label=True, value="English", choices=language_dict, scale=1, interactive=True)
|
| 231 |
target_languaje = gr.Dropdown(visible=visible, label="Target languaje", show_label=True, value="Español", choices=language_dict, scale=1, interactive=True)
|
|
|
|
| 232 |
number_of_speakers = gr.Dropdown(visible=visible, label="Number of speakers", show_label=True, value=10, choices=num_speaker, scale=1, interactive=True)
|
| 233 |
+
subtify_button = gr.Button(size="lg", value="subtify", min_width="10px", scale=0, visible=visible)
|
| 234 |
+
start_block = gr.Textbox(placeholder="Waiting", label="Start block", elem_id="start_block", interactive=False, visible=visible)
|
| 235 |
+
video_donwloaded = gr.Textbox(placeholder="Waiting", label="Video downloaded", elem_id="video_downloaded", interactive=False, visible=visible)
|
| 236 |
+
video_sliced = gr.Textbox(placeholder="Waiting", label="Video sliced", elem_id="video_sliced", interactive=False, visible=visible)
|
| 237 |
+
video_transcribed = gr.Textbox(placeholder="Waiting", label="Video transcribed", elem_id="video_transcribed", interactive=False, visible=visible)
|
| 238 |
+
transcriptions_concatenated = gr.Textbox(placeholder="Waiting", label="Transcriptions concatenated", elem_id="transcriptions_concatenated", interactive=False, visible=visible)
|
| 239 |
+
video_translated = gr.Textbox(placeholder="Waiting", label="Transcription translated", elem_id="transcription_translated", interactive=False, visible=visible)
|
| 240 |
+
video_subtitled = gr.Textbox(placeholder="Waiting", label="Video subtitled", elem_id="video_subtitled", interactive=False, visible=visible)
|
| 241 |
+
original_audio_path = gr.Textbox(label="Original audio path", elem_id="original_audio_path", visible=visible)
|
| 242 |
+
original_video_path = gr.Textbox(label="Original video path", elem_id="original_video_path", visible=visible)
|
| 243 |
+
original_audio_transcribed_path = gr.Textbox(label="Original audio transcribed", elem_id="original_audio_transcribed", visible=visible)
|
| 244 |
+
original_audio_translated_path = gr.Textbox(label="Original audio translated", elem_id="original_audio_translated", visible=visible)
|
| 245 |
+
subtitled_video = gr.Video(label="Subtitled video", elem_id="subtitled_video", visible=visible, interactive=visible)
|
| 246 |
return (
|
| 247 |
"",
|
| 248 |
image,
|
| 249 |
source_languaje,
|
| 250 |
target_languaje,
|
| 251 |
number_of_speakers,
|
| 252 |
+
subtify_button,
|
| 253 |
+
start_block,
|
| 254 |
+
video_donwloaded,
|
| 255 |
+
video_sliced,
|
| 256 |
+
video_transcribed,
|
| 257 |
+
transcriptions_concatenated,
|
| 258 |
+
video_translated,
|
| 259 |
+
video_subtitled,
|
| 260 |
+
original_audio_path,
|
| 261 |
+
original_video_path,
|
| 262 |
+
original_audio_transcribed_path,
|
| 263 |
+
original_audio_translated_path,
|
| 264 |
+
subtitled_video,
|
| 265 |
)
|
| 266 |
|
| 267 |
def get_youtube_thumbnail(url):
|
|
|
|
| 489 |
|
| 490 |
def subtify():
|
| 491 |
with gr.Blocks() as demo:
|
|
|
|
| 492 |
num_speaker = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
|
| 493 |
+
|
| 494 |
+
# Layout
|
| 495 |
gr.Markdown("""# Subtify""")
|
| 496 |
with gr.Row(variant="panel"):
|
| 497 |
url_textbox = gr.Textbox(placeholder="Add video URL here", label="Video URL", elem_id="video_url", scale=1, interactive=True)
|
| 498 |
# copy_button = gr.Button(size="sm", icon="icons/copy.svg", value="", min_width="10px", scale=0)
|
| 499 |
+
delete_button = gr.Button(size="sm", icon="icons/delete.svg", value="", min_width="10px", scale=0)
|
| 500 |
|
| 501 |
visible = False
|
| 502 |
with gr.Row(equal_height=False):
|
|
|
|
| 526 |
|
| 527 |
# Events
|
| 528 |
# copy_button.click(fn=copy_url_from_clipboard, outputs=url_textbox)
|
| 529 |
+
delete_button.click(
|
| 530 |
+
fn=clear_video_url,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
outputs=[
|
| 532 |
+
url_textbox,
|
| 533 |
image,
|
| 534 |
source_languaje,
|
| 535 |
target_languaje,
|
| 536 |
number_of_speakers,
|
| 537 |
subtify_button,
|
| 538 |
+
start_block,
|
| 539 |
+
video_donwloaded,
|
| 540 |
+
video_sliced,
|
| 541 |
+
video_transcribed,
|
| 542 |
+
transcriptions_concatenated,
|
| 543 |
+
video_translated,
|
| 544 |
+
video_subtitled,
|
| 545 |
+
subtitled_video,
|
| 546 |
]
|
| 547 |
)
|
| 548 |
+
url_textbox.change(
|
| 549 |
+
fn=is_valid_url,
|
| 550 |
+
inputs=url_textbox,
|
| 551 |
+
outputs=[image, source_languaje, target_languaje, number_of_speakers, subtify_button]
|
| 552 |
+
)
|
| 553 |
+
subtify_button.click(
|
| 554 |
+
fn=change_visibility_texboxes,
|
| 555 |
+
outputs=[start_block, video_donwloaded, video_sliced, video_transcribed, transcriptions_concatenated, video_translated, video_subtitled]
|
| 556 |
+
)
|
| 557 |
+
start_block.change(
|
| 558 |
+
fn=get_audio_and_video_from_video,
|
| 559 |
+
inputs=[url_textbox],
|
| 560 |
+
outputs=[video_donwloaded, original_audio_path, original_video_path]
|
| 561 |
+
)
|
| 562 |
+
video_donwloaded.change(
|
| 563 |
+
fn=slice_audio,
|
| 564 |
+
inputs=[original_audio_path],
|
| 565 |
+
outputs=[video_sliced]
|
| 566 |
+
)
|
| 567 |
+
video_sliced.change(
|
| 568 |
+
fn=trascribe_audio,
|
| 569 |
+
inputs=[source_languaje],
|
| 570 |
+
outputs=[video_transcribed]
|
| 571 |
+
)
|
| 572 |
+
video_transcribed.change(
|
| 573 |
+
fn=concatenate_transcriptions,
|
| 574 |
+
outputs=[transcriptions_concatenated, original_audio_transcribed_path]
|
| 575 |
+
)
|
| 576 |
+
transcriptions_concatenated.change(
|
| 577 |
+
fn=translate_transcription,
|
| 578 |
+
inputs=[original_audio_transcribed_path, source_languaje, target_languaje],
|
| 579 |
+
outputs=[video_translated, original_audio_translated_path]
|
| 580 |
+
)
|
| 581 |
+
video_translated.change(
|
| 582 |
+
fn=add_translated_subtitles_to_video,
|
| 583 |
+
inputs=[original_video_path, original_audio_path, original_audio_translated_path],
|
| 584 |
+
outputs=[video_subtitled, subtitled_video]
|
| 585 |
+
)
|
| 586 |
|
| 587 |
demo.launch()
|
| 588 |
|
assets/twitch.webp
ADDED
|
assets/youtube-no-thumbnails.webp
ADDED
|
|
assets/youtube_error.webp
ADDED
|