Comment all code
Browse files- .gitignore +0 -1
- app.py +782 -782
.gitignore
CHANGED
|
@@ -14,5 +14,4 @@ sepformer.ipynb
|
|
| 14 |
modelscope.ipynb
|
| 15 |
audio_cache
|
| 16 |
*.png
|
| 17 |
-
*.webp
|
| 18 |
.DS_Store
|
|
|
|
| 14 |
modelscope.ipynb
|
| 15 |
audio_cache
|
| 16 |
*.png
|
|
|
|
| 17 |
.DS_Store
|
app.py
CHANGED
|
@@ -1,695 +1,695 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import argparse
|
| 3 |
-
import os
|
| 4 |
-
import torch
|
| 5 |
-
from time import sleep
|
| 6 |
-
from tqdm import tqdm
|
| 7 |
-
from lang_list import union_language_dict
|
| 8 |
-
# import pyperclip
|
| 9 |
-
from pytube import YouTube
|
| 10 |
-
import re
|
| 11 |
-
from PIL import Image
|
| 12 |
-
import urllib.request
|
| 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 |
-
TRANSCRIBE_AUDIO = True
|
| 20 |
-
CONCATENATE_TRANSCRIPTIONS = True
|
| 21 |
-
TRANSLATE_TRANSCRIPTIONS = True
|
| 22 |
-
ADD_SUBTITLES_TO_VIDEO = True
|
| 23 |
-
REMOVE_FILES = True
|
| 24 |
-
if DEVICE == "cpu":
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
else:
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
YOUTUBE = "youtube"
|
| 37 |
-
TWITCH = "twitch"
|
| 38 |
-
ERROR = "error"
|
| 39 |
-
|
| 40 |
-
try:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
except Exception as e:
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
BACKGROUND_COLOR = "#0b0f19"
|
| 54 |
-
BUTTON_COLOR = "#47515f"
|
| 55 |
-
SVG_COLOR = "#f3f4f6"
|
| 56 |
-
PANEL_COLOR = "#101827"
|
| 57 |
-
PRIMARY_TEXT_COLOR = "#f3f4f6"
|
| 58 |
-
SUBDUED_TEXT_COLOR = "#59616f"
|
| 59 |
-
BACKGROUND_PRIMARY_COLOR = "#1f2937"
|
| 60 |
-
BACKGROUND_SECONDARY_COLOR = "#101827"
|
| 61 |
-
PRIMARY_BODER_COLOR = "#323c4c"
|
| 62 |
-
BLOCK_TITLE_TEXT_COLOR = "#dfe2e6"
|
| 63 |
-
INPUT_BACKGROUND_COLOR = "#2f3947"
|
| 64 |
-
INPUT_BORDER_COLOR = "#313b4b"
|
| 65 |
-
INPUT_PLACEHOLDER_COLOR = "#616977"
|
| 66 |
-
ERROR_BACKGROUND_COLOR = "#101827"
|
| 67 |
-
ERROR_TEXT_COLOR = "#f7f2f2"
|
| 68 |
-
ERROR_BORDER_COLOR = "#9b3339"
|
| 69 |
-
BUTTON_SECONDARY_BACKGROUND_COLOR = "#434d5c"
|
| 70 |
-
BUTTON_SECONDARY_BORDER_COLOR = "#444d5b"
|
| 71 |
-
BUTTON_SECONDARY_TEXT_COLOR = "#c5c9cc"
|
| 72 |
-
RED = "#ff0000"
|
| 73 |
-
GREEN = "#00ff00"
|
| 74 |
-
BLUE = "#0000ff"
|
| 75 |
-
|
| 76 |
-
html_social_media = f'''
|
| 77 |
-
<div style="float: right;">
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
</div>
|
| 179 |
-
'''
|
| 180 |
-
|
| 181 |
-
html_subtify_logo = f"""
|
| 182 |
-
<div style="display: flex; justify-content: center; align-items: center;">
|
| 183 |
-
|
| 184 |
-
</div>
|
| 185 |
-
"""
|
| 186 |
-
|
| 187 |
-
html_buy_me_a_coffe = '''
|
| 188 |
-
<div style="float: right;">
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
</div>
|
| 193 |
-
'''
|
| 194 |
-
|
| 195 |
-
language_dict = union_language_dict()
|
| 196 |
-
|
| 197 |
-
def subtify_no_ui():
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
def remove_all_files():
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
# def paste_url_from_clipboard():
|
| 369 |
-
# return pyperclip.paste()
|
| 370 |
-
|
| 371 |
-
def reset_frontend():
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
def show_auxiliar_block1():
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
def get_youtube_thumbnail(url):
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
def is_valid_youtube_url(url):
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
def is_valid_twitch_url(url):
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
def is_valid_url(url):
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
def change_visibility_texboxes():
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
def get_audio_and_video_from_video(url):
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
def slice_audio(audio_path):
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
def trascribe_audio(source_languaje, number_of_speakers):
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
def concatenate_transcriptions():
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
def translate_transcription(original_audio_transcribed_path, source_languaje, target_languaje):
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
def add_translated_subtitles_to_video(original_video_path, original_audio_path, original_audio_translated_path):
|
| 615 |
-
|
| 616 |
-
|
| 617 |
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
def hide_textbobes_progress_info():
|
| 645 |
-
visible = False
|
| 646 |
-
return (
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
)
|
| 654 |
|
| 655 |
def subtify():
|
| 656 |
with gr.Blocks(
|
| 657 |
theme=gr.themes.Default().set
|
| 658 |
(
|
| 659 |
-
body_background_fill=BACKGROUND_COLOR,
|
| 660 |
-
body_background_fill_dark=BACKGROUND_COLOR,
|
| 661 |
-
body_text_color=PRIMARY_TEXT_COLOR,
|
| 662 |
-
body_text_color_dark=PRIMARY_TEXT_COLOR,
|
| 663 |
-
body_text_color_subdued=SUBDUED_TEXT_COLOR,
|
| 664 |
-
body_text_color_subdued_dark=SUBDUED_TEXT_COLOR,
|
| 665 |
-
background_fill_primary=BACKGROUND_PRIMARY_COLOR,
|
| 666 |
-
background_fill_primary_dark=BACKGROUND_PRIMARY_COLOR,
|
| 667 |
-
background_fill_secondary=BACKGROUND_SECONDARY_COLOR,
|
| 668 |
-
background_fill_secondary_dark=BACKGROUND_SECONDARY_COLOR,
|
| 669 |
-
border_color_primary=PRIMARY_BODER_COLOR,
|
| 670 |
-
border_color_primary_dark=PRIMARY_BODER_COLOR,
|
| 671 |
-
block_background_fill=BACKGROUND_PRIMARY_COLOR,
|
| 672 |
-
block_background_fill_dark=BACKGROUND_PRIMARY_COLOR,
|
| 673 |
-
block_title_text_color=BLOCK_TITLE_TEXT_COLOR,
|
| 674 |
-
block_title_text_color_dark=BLOCK_TITLE_TEXT_COLOR,
|
| 675 |
-
input_background_fill=INPUT_BACKGROUND_COLOR,
|
| 676 |
-
input_background_fill_dark=INPUT_BACKGROUND_COLOR,
|
| 677 |
-
input_border_color=INPUT_BORDER_COLOR,
|
| 678 |
-
input_border_color_dark=INPUT_BORDER_COLOR,
|
| 679 |
-
input_placeholder_color=INPUT_PLACEHOLDER_COLOR,
|
| 680 |
-
input_placeholder_color_dark=INPUT_PLACEHOLDER_COLOR,
|
| 681 |
-
error_background_fill=ERROR_BACKGROUND_COLOR,
|
| 682 |
-
error_background_fill_dark=ERROR_BACKGROUND_COLOR,
|
| 683 |
-
error_text_color=ERROR_TEXT_COLOR,
|
| 684 |
-
error_text_color_dark=ERROR_TEXT_COLOR,
|
| 685 |
-
error_border_color=ERROR_BORDER_COLOR,
|
| 686 |
-
error_border_color_dark=ERROR_BORDER_COLOR,
|
| 687 |
-
button_secondary_background_fill=BUTTON_SECONDARY_BACKGROUND_COLOR,
|
| 688 |
-
button_secondary_background_fill_dark=BUTTON_SECONDARY_BACKGROUND_COLOR,
|
| 689 |
-
button_secondary_border_color=BUTTON_SECONDARY_BORDER_COLOR,
|
| 690 |
-
button_primary_background_fill_dark=BUTTON_SECONDARY_BORDER_COLOR,
|
| 691 |
-
button_secondary_text_color=BUTTON_SECONDARY_TEXT_COLOR,
|
| 692 |
-
button_secondary_text_color_dark=BUTTON_SECONDARY_TEXT_COLOR,
|
| 693 |
)
|
| 694 |
) as demo:
|
| 695 |
num_speaker = []
|
|
@@ -697,112 +697,112 @@ def subtify():
|
|
| 697 |
num_speaker.append(i)
|
| 698 |
|
| 699 |
# Layout
|
| 700 |
-
gr.HTML(html_social_media)
|
| 701 |
gr.HTML("<h1 style='text-align: center;'>Subtify</h1>")
|
| 702 |
-
gr.HTML(html_subtify_logo)
|
| 703 |
-
with gr.Row(variant="panel"):
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
visible = False
|
| 709 |
-
auxiliar_block1 = gr.Textbox(label="Auxiliar block 1", elem_id="auxiliar_block1", interactive=False, visible=visible)
|
| 710 |
-
with gr.Row(equal_height=False):
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
auxiliar_block2 = gr.Textbox(placeholder="Waiting", label="Auxiliar block 2", elem_id="auxiliar_block2", interactive=False, visible=visible)
|
| 721 |
-
with gr.Row():
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
original_audio_path = gr.Textbox(label="Original audio path", elem_id="original_audio_path", visible=visible)
|
| 730 |
-
original_video_path = gr.Textbox(label="Original video path", elem_id="original_video_path", visible=visible)
|
| 731 |
-
original_audio_transcribed_path = gr.Textbox(label="Original audio transcribed", elem_id="original_audio_transcribed", visible=visible)
|
| 732 |
-
original_audio_translated_path = gr.Textbox(label="Original audio translated", elem_id="original_audio_translated", visible=visible)
|
| 733 |
-
subtitled_video = gr.Video(label="Subtitled video", elem_id="subtitled_video", visible=visible, interactive=visible)
|
| 734 |
-
auxiliar_block3 = gr.Textbox(placeholder="Waiting", label="Auxiliar block 3", elem_id="auxiliar_block3", interactive=False, visible=visible)
|
| 735 |
|
| 736 |
# Events
|
| 737 |
# paste_button.click(fn=paste_url_from_clipboard, outputs=url_textbox)
|
| 738 |
-
delete_button.click(
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
)
|
| 758 |
-
url_textbox.change(
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
)
|
| 762 |
-
auxiliar_block1.change(
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
)
|
| 767 |
-
subtify_button.click(
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
)
|
| 771 |
-
auxiliar_block2.change(
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
)
|
| 776 |
-
video_donwloaded_progress_info.change(
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
)
|
| 781 |
-
video_sliced_progress_info.change(
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
)
|
| 786 |
-
video_transcribed_progress_info.change(
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
)
|
| 790 |
-
transcriptions_concatenated_progress_info.change(
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
)
|
| 795 |
-
video_translated_progress_info.change(
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
)
|
| 800 |
-
auxiliar_block3.change(
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
)
|
| 804 |
-
|
| 805 |
-
gr.HTML(html_buy_me_a_coffe)
|
| 806 |
|
| 807 |
demo.launch()
|
| 808 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
# import argparse
|
| 3 |
+
# import os
|
| 4 |
+
# import torch
|
| 5 |
+
# from time import sleep
|
| 6 |
+
# from tqdm import tqdm
|
| 7 |
+
# from lang_list import union_language_dict
|
| 8 |
+
# # import pyperclip
|
| 9 |
+
# from pytube import YouTube
|
| 10 |
+
# import re
|
| 11 |
+
# from PIL import Image
|
| 12 |
+
# import urllib.request
|
| 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 |
+
# TRANSCRIBE_AUDIO = True
|
| 20 |
+
# CONCATENATE_TRANSCRIPTIONS = True
|
| 21 |
+
# TRANSLATE_TRANSCRIPTIONS = True
|
| 22 |
+
# ADD_SUBTITLES_TO_VIDEO = True
|
| 23 |
+
# REMOVE_FILES = True
|
| 24 |
+
# if DEVICE == "cpu":
|
| 25 |
+
# # I supose that I am on huggingface server
|
| 26 |
+
# # Get RAM space
|
| 27 |
+
# ram = int(os.popen("free -m | grep Mem | awk '{print $2}'").read())
|
| 28 |
+
# factor = 1
|
| 29 |
+
# SECONDS = int(ram*factor)
|
| 30 |
+
# print(f"RAM: {ram}, SECONDS: {SECONDS}")
|
| 31 |
+
# else:
|
| 32 |
+
# # I supose that I am on my computer
|
| 33 |
+
# # Get VRAM space
|
| 34 |
+
# SECONDS = 300
|
| 35 |
+
|
| 36 |
+
# YOUTUBE = "youtube"
|
| 37 |
+
# TWITCH = "twitch"
|
| 38 |
+
# ERROR = "error"
|
| 39 |
+
|
| 40 |
+
# try:
|
| 41 |
+
# # Asumiendo que tienes la imagen en una carpeta 'assets' de tu proyecto
|
| 42 |
+
# subtify_logo = Image.open("assets/subtify_logo-scaled.webp")
|
| 43 |
+
# subtify_logo_width, subtify_logo_height = subtify_logo.size
|
| 44 |
+
# factor = 4
|
| 45 |
+
# new_width = subtify_logo_width // factor
|
| 46 |
+
# new_height = subtify_logo_height // factor
|
| 47 |
+
# except Exception as e:
|
| 48 |
+
# print(f"No se pudo cargar la imagen: {e}")
|
| 49 |
+
# # Valores predeterminados en caso de error
|
| 50 |
+
# new_width = 200
|
| 51 |
+
# new_height = 100
|
| 52 |
+
|
| 53 |
+
# BACKGROUND_COLOR = "#0b0f19"
|
| 54 |
+
# BUTTON_COLOR = "#47515f"
|
| 55 |
+
# SVG_COLOR = "#f3f4f6"
|
| 56 |
+
# PANEL_COLOR = "#101827"
|
| 57 |
+
# PRIMARY_TEXT_COLOR = "#f3f4f6"
|
| 58 |
+
# SUBDUED_TEXT_COLOR = "#59616f"
|
| 59 |
+
# BACKGROUND_PRIMARY_COLOR = "#1f2937"
|
| 60 |
+
# BACKGROUND_SECONDARY_COLOR = "#101827"
|
| 61 |
+
# PRIMARY_BODER_COLOR = "#323c4c"
|
| 62 |
+
# BLOCK_TITLE_TEXT_COLOR = "#dfe2e6"
|
| 63 |
+
# INPUT_BACKGROUND_COLOR = "#2f3947"
|
| 64 |
+
# INPUT_BORDER_COLOR = "#313b4b"
|
| 65 |
+
# INPUT_PLACEHOLDER_COLOR = "#616977"
|
| 66 |
+
# ERROR_BACKGROUND_COLOR = "#101827"
|
| 67 |
+
# ERROR_TEXT_COLOR = "#f7f2f2"
|
| 68 |
+
# ERROR_BORDER_COLOR = "#9b3339"
|
| 69 |
+
# BUTTON_SECONDARY_BACKGROUND_COLOR = "#434d5c"
|
| 70 |
+
# BUTTON_SECONDARY_BORDER_COLOR = "#444d5b"
|
| 71 |
+
# BUTTON_SECONDARY_TEXT_COLOR = "#c5c9cc"
|
| 72 |
+
# RED = "#ff0000"
|
| 73 |
+
# GREEN = "#00ff00"
|
| 74 |
+
# BLUE = "#0000ff"
|
| 75 |
+
|
| 76 |
+
# html_social_media = f'''
|
| 77 |
+
# <div style="float: right;">
|
| 78 |
+
# <a href="https://maximofn.com/" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 79 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 576 512">
|
| 80 |
+
# <style>
|
| 81 |
+
# svg {"{"}
|
| 82 |
+
# fill: {SVG_COLOR}
|
| 83 |
+
# {"}"}
|
| 84 |
+
# </style>
|
| 85 |
+
# <path d="M208 80c0-26.5 21.5-48 48-48h64c26.5 0 48 21.5 48 48v64c0 26.5-21.5 48-48 48h-8v40H464c30.9 0 56 25.1 56 56v32h8c26.5 0 48 21.5 48 48v64c0 26.5-21.5 48-48 48H464c-26.5 0-48-21.5-48-48V368c0-26.5 21.5-48 48-48h8V288c0-4.4-3.6-8-8-8H312v40h8c26.5 0 48 21.5 48 48v64c0 26.5-21.5 48-48 48H256c-26.5 0-48-21.5-48-48V368c0-26.5 21.5-48 48-48h8V280H112c-4.4 0-8 3.6-8 8v32h8c26.5 0 48 21.5 48 48v64c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V368c0-26.5 21.5-48 48-48h8V288c0-30.9 25.1-56 56-56H264V192h-8c-26.5 0-48-21.5-48-48V80z"/>
|
| 86 |
+
# </svg>
|
| 87 |
+
# </a>
|
| 88 |
+
# <a href="http://github.com/maximofn" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 89 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 496 512">
|
| 90 |
+
# <style>
|
| 91 |
+
# svg {"{"}
|
| 92 |
+
# fill: {SVG_COLOR}
|
| 93 |
+
# {"}"}
|
| 94 |
+
# </style>
|
| 95 |
+
# <path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/>
|
| 96 |
+
# </svg>
|
| 97 |
+
# </a>
|
| 98 |
+
# <a href="http://linkedin.com/in/MaximoFN/" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 99 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512">
|
| 100 |
+
# <style>
|
| 101 |
+
# svg {"{"}
|
| 102 |
+
# fill: {SVG_COLOR}
|
| 103 |
+
# {"}"}
|
| 104 |
+
# </style>
|
| 105 |
+
# <path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3zM135.4 416H69V202.2h66.5V416zm-33.2-243c-21.3 0-38.5-17.3-38.5-38.5S80.9 96 102.2 96c21.2 0 38.5 17.3 38.5 38.5 0 21.3-17.2 38.5-38.5 38.5zm282.1 243h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9V416z"/>
|
| 106 |
+
# </svg>
|
| 107 |
+
# </a>
|
| 108 |
+
# <a href="http://kaggle.com/maximofn" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 109 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 320 512">
|
| 110 |
+
# <style>
|
| 111 |
+
# svg {"{"}
|
| 112 |
+
# fill: {SVG_COLOR}
|
| 113 |
+
# {"}"}
|
| 114 |
+
# </style>
|
| 115 |
+
# <path d="M304.2 501.5L158.4 320.3 298.2 185c2.6-2.7 1.7-10.5-5.3-10.5h-69.2c-3.5 0-7 1.8-10.5 5.3L80.9 313.5V7.5q0-7.5-7.5-7.5H21.5Q14 0 14 7.5v497q0 7.5 7.5 7.5h51.9q7.5 0 7.5-7.5v-109l30.8-29.3 110.5 140.6c3 3.5 6.5 5.3 10.5 5.3h66.9q5.25 0 6-3z"/>
|
| 116 |
+
# </svg>
|
| 117 |
+
# </a>
|
| 118 |
+
# <a href="https://twitter.com/Maximo_fn" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 119 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">
|
| 120 |
+
# <style>
|
| 121 |
+
# svg {"{"}
|
| 122 |
+
# fill: {SVG_COLOR}
|
| 123 |
+
# {"}"}
|
| 124 |
+
# </style>
|
| 125 |
+
# <path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"/>
|
| 126 |
+
# </svg>
|
| 127 |
+
# </a>
|
| 128 |
+
# <a href="https://www.instagram.com/maximo__fn/" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 129 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512">
|
| 130 |
+
# <style>
|
| 131 |
+
# svg {"{"}
|
| 132 |
+
# fill: {SVG_COLOR}
|
| 133 |
+
# {"}"}
|
| 134 |
+
# </style>
|
| 135 |
+
# <path d="M224.1 141c-63.6 0-114.9 51.3-114.9 114.9s51.3 114.9 114.9 114.9S339 319.5 339 255.9 287.7 141 224.1 141zm0 189.6c-41.1 0-74.7-33.5-74.7-74.7s33.5-74.7 74.7-74.7 74.7 33.5 74.7 74.7-33.6 74.7-74.7 74.7zm146.4-194.3c0 14.9-12 26.8-26.8 26.8-14.9 0-26.8-12-26.8-26.8s12-26.8 26.8-26.8 26.8 12 26.8 26.8zm76.1 27.2c-1.7-35.9-9.9-67.7-36.2-93.9-26.2-26.2-58-34.4-93.9-36.2-37-2.1-147.9-2.1-184.9 0-35.8 1.7-67.6 9.9-93.9 36.1s-34.4 58-36.2 93.9c-2.1 37-2.1 147.9 0 184.9 1.7 35.9 9.9 67.7 36.2 93.9s58 34.4 93.9 36.2c37 2.1 147.9 2.1 184.9 0 35.9-1.7 67.7-9.9 93.9-36.2 26.2-26.2 34.4-58 36.2-93.9 2.1-37 2.1-147.8 0-184.8zM398.8 388c-7.8 19.6-22.9 34.7-42.6 42.6-29.5 11.7-99.5 9-132.1 9s-102.7 2.6-132.1-9c-19.6-7.8-34.7-22.9-42.6-42.6-11.7-29.5-9-99.5-9-132.1s-2.6-102.7 9-132.1c7.8-19.6 22.9-34.7 42.6-42.6 29.5-11.7 99.5-9 132.1-9s102.7-2.6 132.1 9c19.6 7.8 34.7 22.9 42.6 42.6 11.7 29.5 9 99.5 9 132.1s2.7 102.7-9 132.1z"/>
|
| 136 |
+
# </svg>
|
| 137 |
+
# </a>
|
| 138 |
+
# <a href="https://www.youtube.com/channel/UCdQwg2JU_fWRsHn3yIlf3tw" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 139 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 576 512">
|
| 140 |
+
# <style>
|
| 141 |
+
# svg {"{"}
|
| 142 |
+
# fill: {SVG_COLOR}
|
| 143 |
+
# {"}"}
|
| 144 |
+
# </style>
|
| 145 |
+
# <path d="M549.655 124.083c-6.281-23.65-24.787-42.276-48.284-48.597C458.781 64 288 64 288 64S117.22 64 74.629 75.486c-23.497 6.322-42.003 24.947-48.284 48.597-11.412 42.867-11.412 132.305-11.412 132.305s0 89.438 11.412 132.305c6.281 23.65 24.787 41.5 48.284 47.821C117.22 448 288 448 288 448s170.78 0 213.371-11.486c23.497-6.321 42.003-24.171 48.284-47.821 11.412-42.867 11.412-132.305 11.412-132.305s0-89.438-11.412-132.305zm-317.51 213.508V175.185l142.739 81.205-142.739 81.201z"/>
|
| 146 |
+
# </svg>
|
| 147 |
+
# </a>
|
| 148 |
+
# <a href="https://www.facebook.com/profile.php?id=100085177670661" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 149 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">
|
| 150 |
+
# <style>
|
| 151 |
+
# svg {"{"}
|
| 152 |
+
# fill: {SVG_COLOR}
|
| 153 |
+
# {"}"}
|
| 154 |
+
# </style>
|
| 155 |
+
# <path d="M504 256C504 119 393 8 256 8S8 119 8 256c0 123.78 90.69 226.38 209.25 245V327.69h-63V256h63v-54.64c0-62.15 37-96.48 93.67-96.48 27.14 0 55.52 4.84 55.52 4.84v61h-31.28c-30.8 0-40.41 19.12-40.41 38.73V256h68.78l-11 71.69h-57.78V501C413.31 482.38 504 379.78 504 256z"/>
|
| 156 |
+
# </svg>
|
| 157 |
+
# </a>
|
| 158 |
+
# <a href="https://www.tiktok.com/@maximo__fn" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 159 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512">
|
| 160 |
+
# <style>
|
| 161 |
+
# svg {"{"}
|
| 162 |
+
# fill: {SVG_COLOR}
|
| 163 |
+
# {"}"}
|
| 164 |
+
# </style>
|
| 165 |
+
# <path d="M448,209.91a210.06,210.06,0,0,1-122.77-39.25V349.38A162.55,162.55,0,1,1,185,188.31V278.2a74.62,74.62,0,1,0,52.23,71.18V0l88,0a121.18,121.18,0,0,0,1.86,22.17h0A122.18,122.18,0,0,0,381,102.39a121.43,121.43,0,0,0,67,20.14Z"/>
|
| 166 |
+
# </svg>
|
| 167 |
+
# </a>
|
| 168 |
+
# <a href="https://www.twitch.tv/maximofn/" rel="noopener noreferrer" aria-disabled="false" class="sm secondary svelte-cmf5ev" id="component-1" style="flex-grow: 100;" target="_blank">
|
| 169 |
+
# <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">
|
| 170 |
+
# <style>
|
| 171 |
+
# svg {"{"}
|
| 172 |
+
# fill: {SVG_COLOR}
|
| 173 |
+
# {"}"}
|
| 174 |
+
# </style>
|
| 175 |
+
# <path d="M391.17,103.47H352.54v109.7h38.63ZM285,103H246.37V212.75H285ZM120.83,0,24.31,91.42V420.58H140.14V512l96.53-91.42h77.25L487.69,256V0ZM449.07,237.75l-77.22,73.12H294.61l-67.6,64v-64H140.14V36.58H449.07Z"/>
|
| 176 |
+
# </svg>
|
| 177 |
+
# </a>
|
| 178 |
+
# </div>
|
| 179 |
+
# '''
|
| 180 |
+
|
| 181 |
+
# html_subtify_logo = f"""
|
| 182 |
+
# <div style="display: flex; justify-content: center; align-items: center;">
|
| 183 |
+
# <img src='assets/subtify_logo-scaled.webp' width={new_width}px height={new_height}px >
|
| 184 |
+
# </div>
|
| 185 |
+
# """
|
| 186 |
+
|
| 187 |
+
# html_buy_me_a_coffe = '''
|
| 188 |
+
# <div style="float: right;">
|
| 189 |
+
# <a href="https://www.buymeacoffee.com/maximofn" target="_blank">
|
| 190 |
+
# <img src="https://img.shields.io/badge/Buy_Me_A_Coffee-support_my_work-FFDD00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=white&labelColor=101010" alt="buy me a coffe">
|
| 191 |
+
# </a>
|
| 192 |
+
# </div>
|
| 193 |
+
# '''
|
| 194 |
+
|
| 195 |
+
# language_dict = union_language_dict()
|
| 196 |
+
|
| 197 |
+
# def subtify_no_ui():
|
| 198 |
+
# number_works = 6
|
| 199 |
+
# progress_bar = tqdm(total=number_works, desc="Subtify")
|
| 200 |
+
# folder_chunck = "chunks"
|
| 201 |
+
# folder_concatenated = "concatenated_transcriptions"
|
| 202 |
+
# folder_translated_transcriptions = "translated_transcriptions"
|
| 203 |
+
# if not os.path.exists(folder_chunck):
|
| 204 |
+
# os.makedirs(folder_chunck)
|
| 205 |
+
# if not os.path.exists(folder_concatenated):
|
| 206 |
+
# os.makedirs(folder_concatenated)
|
| 207 |
+
# if not os.path.exists(folder_translated_transcriptions):
|
| 208 |
+
# os.makedirs(folder_translated_transcriptions)
|
| 209 |
+
|
| 210 |
+
# ################## Download video and audio ##################
|
| 211 |
+
# if DOWNLOAD:
|
| 212 |
+
# print('*'*NUMBER)
|
| 213 |
+
# # url = "https://www.twitch.tv/videos/1936119752" # twitch Rob Mula 2 horas
|
| 214 |
+
# # url = "https://www.youtube.com/watch?v=yX5EJf4R77s" # ✅ debate, varios hablantes, 3 minutos
|
| 215 |
+
# # url = "https://www.youtube.com/watch?v=cgx0QnXo1OU" # ✅ smart home, un solo hablante, 4:42 minutos
|
| 216 |
+
# # url = "https://www.youtube.com/watch?v=dgOBxhi19T8" # ✅ rob mula, muchos hablantes, 4:28 minutos
|
| 217 |
+
# # url = "https://www.youtube.com/watch?v=Coj72EzmX20" # rob mula, un solo hablante, 16 minutos
|
| 218 |
+
# # url = "https://www.youtube.com/watch?v=Tqth0fKo0_g" # Conversación short
|
| 219 |
+
# url = "https://www.youtube.com/watch?v=h9xPrgTYP_0" # Letitia 40 segundos
|
| 220 |
+
# print(f"Downloading video and audio from {url}")
|
| 221 |
+
# python_file = "download.py"
|
| 222 |
+
# command = f"python {python_file} {url}"
|
| 223 |
+
# os.system(command)
|
| 224 |
+
# sleep(1)
|
| 225 |
+
# print('*'*NUMBER)
|
| 226 |
+
# print("\n\n")
|
| 227 |
+
# progress_bar.update(1)
|
| 228 |
+
|
| 229 |
+
# ################## Slice audio ##################
|
| 230 |
+
# if SLICE_AUDIO:
|
| 231 |
+
# print('*'*NUMBER)
|
| 232 |
+
# print("Slicing audio")
|
| 233 |
+
# python_file = "slice_audio.py"
|
| 234 |
+
# audio = "audios/download_audio.mp3"
|
| 235 |
+
# command = f"python {python_file} {audio} {SECONDS}"
|
| 236 |
+
# os.system(command)
|
| 237 |
+
# print('*'*NUMBER)
|
| 238 |
+
# print("\n\n")
|
| 239 |
+
# progress_bar.update(1)
|
| 240 |
+
|
| 241 |
+
# ################# Transcript slices ##################
|
| 242 |
+
# if TRANSCRIBE_AUDIO:
|
| 243 |
+
# print('*'*NUMBER)
|
| 244 |
+
# print("Transcript slices")
|
| 245 |
+
# chunks_folder = "chunks"
|
| 246 |
+
# if not os.path.exists(chunks_folder):
|
| 247 |
+
# os.makedirs(chunks_folder)
|
| 248 |
+
# python_file = "transcribe.py"
|
| 249 |
+
# chunks_file = "chunks/output_files.txt"
|
| 250 |
+
# number_of_speakers = 10
|
| 251 |
+
# source_languaje = "English"
|
| 252 |
+
# command = f"python {python_file} {chunks_file} {source_languaje} {number_of_speakers} {DEVICE}"
|
| 253 |
+
# os.system(command)
|
| 254 |
+
# if REMOVE_FILES:
|
| 255 |
+
# with open(chunks_file, 'r') as f:
|
| 256 |
+
# files = f.read().splitlines()
|
| 257 |
+
# for file in files:
|
| 258 |
+
# audios_extension = "mp3"
|
| 259 |
+
# file_name, _ = file.split(".")
|
| 260 |
+
# _, file_name = file_name.split("/")
|
| 261 |
+
# vocal = f'{chunks_folder}/{file_name}.{audios_extension}'
|
| 262 |
+
# command = f"rm {vocal}"
|
| 263 |
+
# os.system(command)
|
| 264 |
+
# print('*'*NUMBER)
|
| 265 |
+
# print("\n\n")
|
| 266 |
+
# progress_bar.update(1)
|
| 267 |
+
|
| 268 |
+
# ################## Concatenate transcriptions ##################
|
| 269 |
+
# if CONCATENATE_TRANSCRIPTIONS:
|
| 270 |
+
# print('*'*NUMBER)
|
| 271 |
+
# print("Concatenate transcriptions")
|
| 272 |
+
# folder_concatenated = "concatenated_transcriptions"
|
| 273 |
+
# if not os.path.exists(folder_concatenated):
|
| 274 |
+
# os.makedirs(folder_concatenated)
|
| 275 |
+
|
| 276 |
+
# chunck_file = "chunks/output_files.txt"
|
| 277 |
+
# python_file = "concat_transcriptions.py"
|
| 278 |
+
# command = f"python {python_file} {chunck_file} {SECONDS}"
|
| 279 |
+
# os.system(command)
|
| 280 |
+
# if REMOVE_FILES:
|
| 281 |
+
# with open(chunck_file, 'r') as f:
|
| 282 |
+
# files = f.read().splitlines()
|
| 283 |
+
# for file in files:
|
| 284 |
+
# file_name, _ = file.split(".")
|
| 285 |
+
# _, file_name = file_name.split("/")
|
| 286 |
+
# transcriptions_folder = "transcriptions"
|
| 287 |
+
# transcription_extension = "srt"
|
| 288 |
+
# command = f"rm {transcriptions_folder}/{file_name}.{transcription_extension}"
|
| 289 |
+
# os.system(command)
|
| 290 |
+
# print('*'*NUMBER)
|
| 291 |
+
# print("\n\n")
|
| 292 |
+
# progress_bar.update(1)
|
| 293 |
+
|
| 294 |
+
# ################## Translate transcription ##################
|
| 295 |
+
# target_languaje = "Español"
|
| 296 |
+
# if TRANSLATE_TRANSCRIPTIONS:
|
| 297 |
+
# print('*'*NUMBER)
|
| 298 |
+
# print("Translate transcription")
|
| 299 |
+
# transcription_file = "concatenated_transcriptions/download_audio.srt"
|
| 300 |
+
# source_languaje = "English"
|
| 301 |
+
# python_file = "translate_transcriptions.py"
|
| 302 |
+
# command = f"python {python_file} {transcription_file} --source_languaje {source_languaje} --target_languaje {target_languaje} --device {DEVICE}"
|
| 303 |
+
# os.system(command)
|
| 304 |
+
# if REMOVE_FILES:
|
| 305 |
+
# if os.path.exists(transcription_file):
|
| 306 |
+
# command = f"rm {transcription_file}"
|
| 307 |
+
# os.system(command)
|
| 308 |
+
# print('*'*NUMBER)
|
| 309 |
+
# print("\n\n")
|
| 310 |
+
# progress_bar.update(1)
|
| 311 |
+
|
| 312 |
+
# ################## Add subtitles to video ##################
|
| 313 |
+
# if ADD_SUBTITLES_TO_VIDEO:
|
| 314 |
+
# print('*'*NUMBER)
|
| 315 |
+
# print("Add subtitles to video")
|
| 316 |
+
# python_file = "add_subtitles_to_video.py"
|
| 317 |
+
# transcription_file = f"translated_transcriptions/download_audio_{target_languaje}.srt"
|
| 318 |
+
# input_video_file = "videos/download_video.mp4"
|
| 319 |
+
# input_audio_file = "audios/download_audio.mp3"
|
| 320 |
+
# command = f"python {python_file} {transcription_file} {input_video_file} {input_audio_file}"
|
| 321 |
+
# os.system(command)
|
| 322 |
+
# if REMOVE_FILES:
|
| 323 |
+
# if os.path.exists(input_video_file):
|
| 324 |
+
# command = f"rm {input_video_file}"
|
| 325 |
+
# os.system(command)
|
| 326 |
+
# if os.path.exists(input_audio_file):
|
| 327 |
+
# command = f"rm {input_audio_file}"
|
| 328 |
+
# os.system(command)
|
| 329 |
+
# if os.path.exists(transcription_file):
|
| 330 |
+
# command = f"rm {transcription_file}"
|
| 331 |
+
# os.system(command)
|
| 332 |
+
# if os.path.exists("chunks/output_files.txt"):
|
| 333 |
+
# command = f"rm chunks/output_files.txt"
|
| 334 |
+
# os.system(command)
|
| 335 |
+
# if os.path.exists("chunks"):
|
| 336 |
+
# command = f"rm -r chunks"
|
| 337 |
+
# os.system(command)
|
| 338 |
+
# if os.path.exists("vocals/speakers.txt"):
|
| 339 |
+
# command = f"rm vocals/speakers.txt"
|
| 340 |
+
# os.system(command)
|
| 341 |
+
# print('*'*NUMBER)
|
| 342 |
+
# print("\n\n")
|
| 343 |
+
# progress_bar.update(1)
|
| 344 |
+
|
| 345 |
+
# def remove_all_files():
|
| 346 |
+
# if os.path.exists("audios"):
|
| 347 |
+
# command = f"rm -r audios"
|
| 348 |
+
# os.system(command)
|
| 349 |
+
# if os.path.exists("chunks"):
|
| 350 |
+
# command = f"rm -r chunks"
|
| 351 |
+
# os.system(command)
|
| 352 |
+
# if os.path.exists("concatenated_transcriptions"):
|
| 353 |
+
# command = f"rm -r concatenated_transcriptions"
|
| 354 |
+
# os.system(command)
|
| 355 |
+
# if os.path.exists("transcriptions"):
|
| 356 |
+
# command = f"rm -r transcriptions"
|
| 357 |
+
# os.system(command)
|
| 358 |
+
# if os.path.exists("translated_transcriptions"):
|
| 359 |
+
# command = f"rm -r translated_transcriptions"
|
| 360 |
+
# os.system(command)
|
| 361 |
+
# if os.path.exists("videos"):
|
| 362 |
+
# command = f"rm -r videos"
|
| 363 |
+
# os.system(command)
|
| 364 |
+
# if os.path.exists("vocals"):
|
| 365 |
+
# command = f"rm -r vocals"
|
| 366 |
+
# os.system(command)
|
| 367 |
+
|
| 368 |
+
# # def paste_url_from_clipboard():
|
| 369 |
+
# # return pyperclip.paste()
|
| 370 |
+
|
| 371 |
+
# def reset_frontend():
|
| 372 |
+
# visible = False
|
| 373 |
+
# return (
|
| 374 |
+
# "",
|
| 375 |
+
# gr.Image(visible=visible),
|
| 376 |
+
# gr.Dropdown(visible=visible),
|
| 377 |
+
# gr.Dropdown(visible=visible),
|
| 378 |
+
# gr.Dropdown(visible=visible),
|
| 379 |
+
# gr.Accordion(visible=visible),
|
| 380 |
+
# gr.Button(visible=visible),
|
| 381 |
+
# gr.Textbox(visible=visible),
|
| 382 |
+
# gr.Textbox(visible=visible),
|
| 383 |
+
# gr.Textbox(visible=visible),
|
| 384 |
+
# gr.Textbox(visible=visible),
|
| 385 |
+
# gr.Textbox(visible=visible),
|
| 386 |
+
# gr.Textbox(visible=visible),
|
| 387 |
+
# gr.Textbox(visible=visible),
|
| 388 |
+
# gr.Textbox(visible=visible),
|
| 389 |
+
# gr.Textbox(visible=visible),
|
| 390 |
+
# gr.Textbox(visible=visible),
|
| 391 |
+
# gr.Textbox(visible=visible),
|
| 392 |
+
# gr.Video(visible=visible),
|
| 393 |
+
# )
|
| 394 |
+
|
| 395 |
+
# def show_auxiliar_block1():
|
| 396 |
+
# return gr.Textbox(value="URL checked", visible=False)
|
| 397 |
+
|
| 398 |
+
# def get_youtube_thumbnail(url):
|
| 399 |
+
# yt = YouTube(url)
|
| 400 |
+
# thumbnail_url = yt.thumbnail_url
|
| 401 |
+
# return thumbnail_url
|
| 402 |
+
|
| 403 |
+
# def is_valid_youtube_url(url):
|
| 404 |
+
# # This regular expression should match the following YouTube URL formats:
|
| 405 |
+
# # - https://youtube.com/watch?v=video_id
|
| 406 |
+
# # - https://www.youtube.com/watch?v=video_id
|
| 407 |
+
# # - https://youtu.be/video_id
|
| 408 |
+
# patron_youtube = r'(https?://)?(www\.)?(youtube\.com/watch\?v=|youtu\.be/)[\w-]+'
|
| 409 |
+
# return bool(re.match(patron_youtube, url))
|
| 410 |
+
|
| 411 |
+
# def is_valid_twitch_url(url):
|
| 412 |
+
# # This regular expression should match the following Twitch URL formats:
|
| 413 |
+
# # - https://twitch.tv/channel_name
|
| 414 |
+
# # - https://www.twitch.tv/channel_name
|
| 415 |
+
# # - https://twitch.tv/videos/video_id
|
| 416 |
+
# twitch_pattern = r'(https?://)?(www\.)?twitch\.tv/(videos/\d+|\w+)'
|
| 417 |
+
# return bool(re.match(twitch_pattern, url))
|
| 418 |
+
|
| 419 |
+
# def is_valid_url(url):
|
| 420 |
+
# num_speaker = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
|
| 421 |
+
# source_languaje = gr.Dropdown(visible=True, label="Source languaje", show_label=True, value="English", choices=language_dict, scale=1, interactive=True)
|
| 422 |
+
# target_languaje = gr.Dropdown(visible=True, label="Target languaje", show_label=True, value="Español", choices=language_dict, scale=1, interactive=True)
|
| 423 |
+
# advanced_setings = gr.Accordion(visible=True)
|
| 424 |
+
# number_of_speakers = gr.Dropdown(visible=True, label="Number of speakers", show_label=True, value=10, choices=num_speaker, scale=1, interactive=True)
|
| 425 |
+
# subtify_button = gr.Button(size="lg", value="subtify", min_width="10px", scale=0, visible=True)
|
| 426 |
+
|
| 427 |
+
# # Youtube
|
| 428 |
+
# if "youtube" in url.lower() or "youtu.be" in url.lower():
|
| 429 |
+
# if is_valid_youtube_url(url):
|
| 430 |
+
# thumbnail = get_youtube_thumbnail(url)
|
| 431 |
+
# if thumbnail:
|
| 432 |
+
# return (
|
| 433 |
+
# gr.Image(value=thumbnail, visible=True, show_download_button=False, container=False),
|
| 434 |
+
# source_languaje,
|
| 435 |
+
# target_languaje,
|
| 436 |
+
# advanced_setings,
|
| 437 |
+
# number_of_speakers,
|
| 438 |
+
# subtify_button,
|
| 439 |
+
# )
|
| 440 |
+
# else:
|
| 441 |
+
# return (
|
| 442 |
+
# gr.Image(value="assets/youtube-no-thumbnails.webp", visible=True, show_download_button=False, container=False),
|
| 443 |
+
# source_languaje,
|
| 444 |
+
# target_languaje,
|
| 445 |
+
# advanced_setings,
|
| 446 |
+
# number_of_speakers,
|
| 447 |
+
# subtify_button,
|
| 448 |
+
# )
|
| 449 |
|
| 450 |
+
# # Twitch
|
| 451 |
+
# elif "twitch" in url.lower() or "twitch.tv" in url.lower():
|
| 452 |
+
# if is_valid_twitch_url(url):
|
| 453 |
+
# return (
|
| 454 |
+
# gr.Image(value="assets/twitch.webp", visible=True, show_download_button=False, container=False),
|
| 455 |
+
# source_languaje,
|
| 456 |
+
# target_languaje,
|
| 457 |
+
# advanced_setings,
|
| 458 |
+
# number_of_speakers,
|
| 459 |
+
# subtify_button,
|
| 460 |
+
# )
|
| 461 |
|
| 462 |
+
# # Error
|
| 463 |
+
# visible = False
|
| 464 |
+
# image = gr.Image(value="assets/youtube_error.webp", visible=visible, show_download_button=False, container=False)
|
| 465 |
+
# source_languaje = gr.Dropdown(visible=visible, label="Source languaje", show_label=True, value="English", choices=language_dict, scale=1, interactive=True)
|
| 466 |
+
# target_languaje = gr.Dropdown(visible=visible, label="Target languaje", show_label=True, value="Español", choices=language_dict, scale=1, interactive=True)
|
| 467 |
+
# advanced_setings = gr.Accordion(visible=visible)
|
| 468 |
+
# number_of_speakers = gr.Dropdown(visible=visible, label="Number of speakers", show_label=True, value=10, choices=num_speaker, scale=1, interactive=True)
|
| 469 |
+
# subtify_button = gr.Button(size="lg", value="subtify", min_width="10px", scale=0, visible=visible)
|
| 470 |
+
# return (
|
| 471 |
+
# image,
|
| 472 |
+
# source_languaje,
|
| 473 |
+
# target_languaje,
|
| 474 |
+
# advanced_setings,
|
| 475 |
+
# number_of_speakers,
|
| 476 |
+
# subtify_button,
|
| 477 |
+
# )
|
| 478 |
+
|
| 479 |
+
# def change_visibility_texboxes():
|
| 480 |
+
|
| 481 |
+
# return (
|
| 482 |
+
# gr.Textbox(value="Done"),
|
| 483 |
+
# gr.Textbox(visible=True),
|
| 484 |
+
# gr.Textbox(visible=True),
|
| 485 |
+
# gr.Textbox(visible=True),
|
| 486 |
+
# gr.Textbox(visible=True),
|
| 487 |
+
# gr.Textbox(visible=True),
|
| 488 |
+
# gr.Textbox(visible=True),
|
| 489 |
+
# gr.Textbox(visible=False),
|
| 490 |
+
# )
|
| 491 |
+
|
| 492 |
+
# def get_audio_and_video_from_video(url):
|
| 493 |
+
# print('*'*NUMBER)
|
| 494 |
+
# print(f"Downloading video and audio from {url}")
|
| 495 |
+
|
| 496 |
+
# audios_folder = "audios"
|
| 497 |
+
# videos_folder = "videos"
|
| 498 |
+
# if not os.path.exists(audios_folder):
|
| 499 |
+
# os.makedirs(audios_folder)
|
| 500 |
+
# if not os.path.exists(videos_folder):
|
| 501 |
+
# os.makedirs(videos_folder)
|
| 502 |
|
| 503 |
+
# python_file = "download.py"
|
| 504 |
+
# command = f"python {python_file} {url}"
|
| 505 |
+
# os.system(command)
|
| 506 |
+
# sleep(1)
|
| 507 |
+
|
| 508 |
+
# audio = "audios/download_audio.mp3"
|
| 509 |
+
# video = "videos/download_video.mp4"
|
| 510 |
+
|
| 511 |
+
# return (
|
| 512 |
+
# gr.Textbox(value="Ok"),
|
| 513 |
+
# gr.Textbox(value=audio),
|
| 514 |
+
# gr.Textbox(value=video),
|
| 515 |
+
# )
|
| 516 |
+
|
| 517 |
+
# def slice_audio(audio_path):
|
| 518 |
+
# print('*'*NUMBER)
|
| 519 |
+
# print("Slicing audio")
|
| 520 |
+
|
| 521 |
+
# folder_vocals = "vocals"
|
| 522 |
+
# folder_chunck = "chunks"
|
| 523 |
+
# if not os.path.exists(folder_vocals):
|
| 524 |
+
# os.makedirs(folder_vocals)
|
| 525 |
+
# if not os.path.exists(folder_chunck):
|
| 526 |
+
# os.makedirs(folder_chunck)
|
| 527 |
|
| 528 |
+
# python_file = "slice_audio.py"
|
| 529 |
+
# command = f"python {python_file} {audio_path} {SECONDS}"
|
| 530 |
+
# os.system(command)
|
| 531 |
+
|
| 532 |
+
# return (
|
| 533 |
+
# gr.Textbox(value="Ok")
|
| 534 |
+
# )
|
| 535 |
+
|
| 536 |
+
# def trascribe_audio(source_languaje, number_of_speakers):
|
| 537 |
+
# print('*'*NUMBER)
|
| 538 |
+
# print("Transcript slices")
|
| 539 |
+
|
| 540 |
+
# folder_chunks = "chunks"
|
| 541 |
+
# python_file = "transcribe.py"
|
| 542 |
+
# chunks_file = "chunks/output_files.txt"
|
| 543 |
+
# command = f"python {python_file} {chunks_file} {source_languaje} {number_of_speakers} {DEVICE}"
|
| 544 |
+
# os.system(command)
|
| 545 |
+
|
| 546 |
+
# with open(chunks_file, 'r') as f:
|
| 547 |
+
# files = f.read().splitlines()
|
| 548 |
+
# for file in files:
|
| 549 |
+
# audios_extension = "mp3"
|
| 550 |
+
# file_name, _ = file.split(".")
|
| 551 |
+
# _, file_name = file_name.split("/")
|
| 552 |
+
# vocal = f'{folder_chunks}/{file_name}.{audios_extension}'
|
| 553 |
+
# command = f"rm {vocal}"
|
| 554 |
+
# os.system(command)
|
| 555 |
+
|
| 556 |
+
# return (
|
| 557 |
+
# gr.Textbox(value="Ok")
|
| 558 |
+
# )
|
| 559 |
+
|
| 560 |
+
# def concatenate_transcriptions():
|
| 561 |
+
# print('*'*NUMBER)
|
| 562 |
+
# print("Concatenate transcriptions")
|
| 563 |
+
|
| 564 |
+
# folder_concatenated = "concatenated_transcriptions"
|
| 565 |
+
# if not os.path.exists(folder_concatenated):
|
| 566 |
+
# os.makedirs(folder_concatenated)
|
| 567 |
+
|
| 568 |
+
# chunck_file = "chunks/output_files.txt"
|
| 569 |
+
# python_file = "concat_transcriptions.py"
|
| 570 |
+
# command = f"python {python_file} {chunck_file} {SECONDS}"
|
| 571 |
+
# os.system(command)
|
| 572 |
+
|
| 573 |
+
# with open(chunck_file, 'r') as f:
|
| 574 |
+
# files = f.read().splitlines()
|
| 575 |
+
# for file in files:
|
| 576 |
+
# file_name, _ = file.split(".")
|
| 577 |
+
# _, file_name = file_name.split("/")
|
| 578 |
+
# transcriptions_folder = "transcriptions"
|
| 579 |
+
# transcription_extension = "srt"
|
| 580 |
+
# command = f"rm {transcriptions_folder}/{file_name}.{transcription_extension}"
|
| 581 |
+
# os.system(command)
|
| 582 |
+
|
| 583 |
+
# audio_transcribed = "concatenated_transcriptions/download_audio.srt"
|
| 584 |
+
|
| 585 |
+
# return (
|
| 586 |
+
# gr.Textbox(value="Ok"),
|
| 587 |
+
# gr.Textbox(value=audio_transcribed),
|
| 588 |
+
# )
|
| 589 |
+
|
| 590 |
+
# def translate_transcription(original_audio_transcribed_path, source_languaje, target_languaje):
|
| 591 |
+
# print('*'*NUMBER)
|
| 592 |
+
# print("Translate transcription")
|
| 593 |
+
|
| 594 |
+
# folder_translated_transcriptions = "translated_transcriptions"
|
| 595 |
+
# if not os.path.exists(folder_translated_transcriptions):
|
| 596 |
+
# os.makedirs(folder_translated_transcriptions)
|
| 597 |
+
|
| 598 |
+
# python_file = "translate_transcriptions.py"
|
| 599 |
+
# command = f"python {python_file} {original_audio_transcribed_path} --source_languaje {source_languaje} --target_languaje {target_languaje} --device {DEVICE}"
|
| 600 |
+
# os.system(command)
|
| 601 |
+
|
| 602 |
+
# translated_transcription = f"translated_transcriptions/download_audio_{target_languaje}.srt"
|
| 603 |
+
|
| 604 |
+
# transcription_file = "concatenated_transcriptions/download_audio.srt"
|
| 605 |
+
# if os.path.exists(transcription_file):
|
| 606 |
+
# command = f"rm {transcription_file}"
|
| 607 |
+
# os.system(command)
|
| 608 |
+
|
| 609 |
+
# return (
|
| 610 |
+
# gr.Textbox(value="Ok"),
|
| 611 |
+
# gr.Textbox(value=translated_transcription)
|
| 612 |
+
# )
|
| 613 |
+
|
| 614 |
+
# def add_translated_subtitles_to_video(original_video_path, original_audio_path, original_audio_translated_path):
|
| 615 |
+
# print('*'*NUMBER)
|
| 616 |
+
# print("Add subtitles to video")
|
| 617 |
|
| 618 |
+
# python_file = "add_subtitles_to_video.py"
|
| 619 |
+
# command = f"python {python_file} {original_audio_translated_path} {original_video_path} {original_audio_path}"
|
| 620 |
+
# os.system(command)
|
| 621 |
+
|
| 622 |
+
# if os.path.exists(original_video_path):
|
| 623 |
+
# command = f"rm {original_video_path}"
|
| 624 |
+
# os.system(command)
|
| 625 |
+
# if os.path.exists(original_audio_path):
|
| 626 |
+
# command = f"rm {original_audio_path}"
|
| 627 |
+
# os.system(command)
|
| 628 |
+
# if os.path.exists(original_audio_translated_path):
|
| 629 |
+
# command = f"rm {original_audio_translated_path}"
|
| 630 |
+
# os.system(command)
|
| 631 |
+
# if os.path.exists("chunks/output_files.txt"):
|
| 632 |
+
# command = f"rm chunks/output_files.txt"
|
| 633 |
+
# os.system(command)
|
| 634 |
+
|
| 635 |
+
# subtitled_video = "videos/download_video_with_subtitles.mp4"
|
| 636 |
|
| 637 |
+
# visible = False
|
| 638 |
+
# return (
|
| 639 |
+
# gr.Video(value=subtitled_video, visible=True),
|
| 640 |
+
# gr.Textbox(value="Ok", visible=visible),
|
| 641 |
+
# gr.Textbox(value="Ok"),
|
| 642 |
+
# )
|
| 643 |
+
|
| 644 |
+
# def hide_textbobes_progress_info():
|
| 645 |
+
# visible = False
|
| 646 |
+
# return (
|
| 647 |
+
# gr.Textbox(value="Waiting", visible=visible),
|
| 648 |
+
# gr.Textbox(value="Waiting", visible=visible),
|
| 649 |
+
# gr.Textbox(value="Waiting", visible=visible),
|
| 650 |
+
# gr.Textbox(value="Waiting", visible=visible),
|
| 651 |
+
# gr.Textbox(value="Waiting", visible=visible),
|
| 652 |
+
# gr.Textbox(value="Waiting", visible=visible),
|
| 653 |
+
# )
|
| 654 |
|
| 655 |
def subtify():
|
| 656 |
with gr.Blocks(
|
| 657 |
theme=gr.themes.Default().set
|
| 658 |
(
|
| 659 |
+
# body_background_fill=BACKGROUND_COLOR,
|
| 660 |
+
# body_background_fill_dark=BACKGROUND_COLOR,
|
| 661 |
+
# body_text_color=PRIMARY_TEXT_COLOR,
|
| 662 |
+
# body_text_color_dark=PRIMARY_TEXT_COLOR,
|
| 663 |
+
# body_text_color_subdued=SUBDUED_TEXT_COLOR,
|
| 664 |
+
# body_text_color_subdued_dark=SUBDUED_TEXT_COLOR,
|
| 665 |
+
# background_fill_primary=BACKGROUND_PRIMARY_COLOR,
|
| 666 |
+
# background_fill_primary_dark=BACKGROUND_PRIMARY_COLOR,
|
| 667 |
+
# background_fill_secondary=BACKGROUND_SECONDARY_COLOR,
|
| 668 |
+
# background_fill_secondary_dark=BACKGROUND_SECONDARY_COLOR,
|
| 669 |
+
# border_color_primary=PRIMARY_BODER_COLOR,
|
| 670 |
+
# border_color_primary_dark=PRIMARY_BODER_COLOR,
|
| 671 |
+
# block_background_fill=BACKGROUND_PRIMARY_COLOR,
|
| 672 |
+
# block_background_fill_dark=BACKGROUND_PRIMARY_COLOR,
|
| 673 |
+
# block_title_text_color=BLOCK_TITLE_TEXT_COLOR,
|
| 674 |
+
# block_title_text_color_dark=BLOCK_TITLE_TEXT_COLOR,
|
| 675 |
+
# input_background_fill=INPUT_BACKGROUND_COLOR,
|
| 676 |
+
# input_background_fill_dark=INPUT_BACKGROUND_COLOR,
|
| 677 |
+
# input_border_color=INPUT_BORDER_COLOR,
|
| 678 |
+
# input_border_color_dark=INPUT_BORDER_COLOR,
|
| 679 |
+
# input_placeholder_color=INPUT_PLACEHOLDER_COLOR,
|
| 680 |
+
# input_placeholder_color_dark=INPUT_PLACEHOLDER_COLOR,
|
| 681 |
+
# error_background_fill=ERROR_BACKGROUND_COLOR,
|
| 682 |
+
# error_background_fill_dark=ERROR_BACKGROUND_COLOR,
|
| 683 |
+
# error_text_color=ERROR_TEXT_COLOR,
|
| 684 |
+
# error_text_color_dark=ERROR_TEXT_COLOR,
|
| 685 |
+
# error_border_color=ERROR_BORDER_COLOR,
|
| 686 |
+
# error_border_color_dark=ERROR_BORDER_COLOR,
|
| 687 |
+
# button_secondary_background_fill=BUTTON_SECONDARY_BACKGROUND_COLOR,
|
| 688 |
+
# button_secondary_background_fill_dark=BUTTON_SECONDARY_BACKGROUND_COLOR,
|
| 689 |
+
# button_secondary_border_color=BUTTON_SECONDARY_BORDER_COLOR,
|
| 690 |
+
# button_primary_background_fill_dark=BUTTON_SECONDARY_BORDER_COLOR,
|
| 691 |
+
# button_secondary_text_color=BUTTON_SECONDARY_TEXT_COLOR,
|
| 692 |
+
# button_secondary_text_color_dark=BUTTON_SECONDARY_TEXT_COLOR,
|
| 693 |
)
|
| 694 |
) as demo:
|
| 695 |
num_speaker = []
|
|
|
|
| 697 |
num_speaker.append(i)
|
| 698 |
|
| 699 |
# Layout
|
| 700 |
+
# gr.HTML(html_social_media)
|
| 701 |
gr.HTML("<h1 style='text-align: center;'>Subtify</h1>")
|
| 702 |
+
# gr.HTML(html_subtify_logo)
|
| 703 |
+
# with gr.Row(variant="panel"):
|
| 704 |
+
# url_textbox = gr.Textbox(placeholder="Add video URL here and wait a moment", label="Video URL", elem_id="video_url", scale=1, interactive=True)
|
| 705 |
+
# # paste_button = gr.Button(size="sm", icon="icons/paste.svg", value="paste", min_width="10px", scale=0)
|
| 706 |
+
# delete_button = gr.Button(size="sm", icon="icons/delete.svg", value="clear", min_width="10px", scale=0)
|
| 707 |
+
|
| 708 |
+
# visible = False
|
| 709 |
+
# auxiliar_block1 = gr.Textbox(label="Auxiliar block 1", elem_id="auxiliar_block1", interactive=False, visible=visible)
|
| 710 |
+
# with gr.Row(equal_height=False):
|
| 711 |
+
# image = gr.Image(visible=visible, scale=1)
|
| 712 |
+
# with gr.Column():
|
| 713 |
+
# with gr.Row():
|
| 714 |
+
# source_languaje = gr.Dropdown(visible=visible, label="Source languaje", show_label=True, value="English", choices=language_dict, scale=1, interactive=True, info="Language of the video")
|
| 715 |
+
# target_languaje = gr.Dropdown(visible=visible, label="Target languaje", show_label=True, value="Español", choices=language_dict, scale=1, interactive=True, info="Language to translate the subtitles")
|
| 716 |
+
# with gr.Accordion("Advanced settings", open=False, visible=visible) as Advanced_setings:
|
| 717 |
+
# number_of_speakers = gr.Dropdown(visible=visible, label="Number of speakers", show_label=True, value=10, choices=num_speaker, scale=1, interactive=True, info="Number of speakers in the video, if you don't know, select 10")
|
| 718 |
+
# subtify_button = gr.Button(size="lg", value="subtify", min_width="10px", scale=0, visible=visible)
|
| 719 |
+
|
| 720 |
+
# auxiliar_block2 = gr.Textbox(placeholder="Waiting", label="Auxiliar block 2", elem_id="auxiliar_block2", interactive=False, visible=visible)
|
| 721 |
+
# with gr.Row():
|
| 722 |
+
# video_donwloaded_progress_info = gr.Textbox(placeholder="Waiting", label="Video download progress info", elem_id="video_donwloaded_progress_info", interactive=False, visible=visible)
|
| 723 |
+
# video_sliced_progress_info = gr.Textbox(placeholder="Waiting", label="Video slice progress info", elem_id="video_sliced_progress_info", interactive=False, visible=visible)
|
| 724 |
+
# video_transcribed_progress_info = gr.Textbox(placeholder="Waiting", label="Transcribe progress info", elem_id="video_transcribed_progress_info", interactive=False, visible=visible)
|
| 725 |
+
# transcriptions_concatenated_progress_info = gr.Textbox(placeholder="Waiting", label="Concatenate progress info", elem_id="transcriptions_concatenated_progress_info", interactive=False, visible=visible)
|
| 726 |
+
# video_translated_progress_info = gr.Textbox(placeholder="Waiting", label="Translate progress info", elem_id="transcription_translated_progress_info", interactive=False, visible=visible)
|
| 727 |
+
# video_subtitled_progress_info = gr.Textbox(placeholder="Waiting", label="Video subtitle progress info", elem_id="video_subtitled_progress_info", interactive=False, visible=visible)
|
| 728 |
+
|
| 729 |
+
# original_audio_path = gr.Textbox(label="Original audio path", elem_id="original_audio_path", visible=visible)
|
| 730 |
+
# original_video_path = gr.Textbox(label="Original video path", elem_id="original_video_path", visible=visible)
|
| 731 |
+
# original_audio_transcribed_path = gr.Textbox(label="Original audio transcribed", elem_id="original_audio_transcribed", visible=visible)
|
| 732 |
+
# original_audio_translated_path = gr.Textbox(label="Original audio translated", elem_id="original_audio_translated", visible=visible)
|
| 733 |
+
# subtitled_video = gr.Video(label="Subtitled video", elem_id="subtitled_video", visible=visible, interactive=visible)
|
| 734 |
+
# auxiliar_block3 = gr.Textbox(placeholder="Waiting", label="Auxiliar block 3", elem_id="auxiliar_block3", interactive=False, visible=visible)
|
| 735 |
|
| 736 |
# Events
|
| 737 |
# paste_button.click(fn=paste_url_from_clipboard, outputs=url_textbox)
|
| 738 |
+
# delete_button.click(
|
| 739 |
+
# fn=reset_frontend,
|
| 740 |
+
# outputs=[
|
| 741 |
+
# url_textbox,
|
| 742 |
+
# image,
|
| 743 |
+
# source_languaje,
|
| 744 |
+
# target_languaje,
|
| 745 |
+
# Advanced_setings,
|
| 746 |
+
# number_of_speakers,
|
| 747 |
+
# subtify_button,
|
| 748 |
+
# auxiliar_block2,
|
| 749 |
+
# video_donwloaded_progress_info,
|
| 750 |
+
# video_sliced_progress_info,
|
| 751 |
+
# video_transcribed_progress_info,
|
| 752 |
+
# transcriptions_concatenated_progress_info,
|
| 753 |
+
# video_translated_progress_info,
|
| 754 |
+
# video_subtitled_progress_info,
|
| 755 |
+
# subtitled_video,
|
| 756 |
+
# ]
|
| 757 |
+
# )
|
| 758 |
+
# url_textbox.change(
|
| 759 |
+
# fn=show_auxiliar_block1,
|
| 760 |
+
# outputs=[auxiliar_block1]
|
| 761 |
+
# )
|
| 762 |
+
# auxiliar_block1.change(
|
| 763 |
+
# fn=is_valid_url,
|
| 764 |
+
# inputs=url_textbox,
|
| 765 |
+
# outputs=[image, source_languaje, target_languaje, Advanced_setings, number_of_speakers, subtify_button]
|
| 766 |
+
# )
|
| 767 |
+
# subtify_button.click(
|
| 768 |
+
# fn=change_visibility_texboxes,
|
| 769 |
+
# outputs=[auxiliar_block2, video_donwloaded_progress_info, video_sliced_progress_info, video_transcribed_progress_info, transcriptions_concatenated_progress_info, video_translated_progress_info, video_subtitled_progress_info, auxiliar_block1]
|
| 770 |
+
# )
|
| 771 |
+
# auxiliar_block2.change(
|
| 772 |
+
# fn=get_audio_and_video_from_video,
|
| 773 |
+
# inputs=[url_textbox],
|
| 774 |
+
# outputs=[video_donwloaded_progress_info, original_audio_path, original_video_path]
|
| 775 |
+
# )
|
| 776 |
+
# video_donwloaded_progress_info.change(
|
| 777 |
+
# fn=slice_audio,
|
| 778 |
+
# inputs=[original_audio_path],
|
| 779 |
+
# outputs=[video_sliced_progress_info]
|
| 780 |
+
# )
|
| 781 |
+
# video_sliced_progress_info.change(
|
| 782 |
+
# fn=trascribe_audio,
|
| 783 |
+
# inputs=[source_languaje, number_of_speakers],
|
| 784 |
+
# outputs=[video_transcribed_progress_info]
|
| 785 |
+
# )
|
| 786 |
+
# video_transcribed_progress_info.change(
|
| 787 |
+
# fn=concatenate_transcriptions,
|
| 788 |
+
# outputs=[transcriptions_concatenated_progress_info, original_audio_transcribed_path]
|
| 789 |
+
# )
|
| 790 |
+
# transcriptions_concatenated_progress_info.change(
|
| 791 |
+
# fn=translate_transcription,
|
| 792 |
+
# inputs=[original_audio_transcribed_path, source_languaje, target_languaje],
|
| 793 |
+
# outputs=[video_translated_progress_info, original_audio_translated_path]
|
| 794 |
+
# )
|
| 795 |
+
# video_translated_progress_info.change(
|
| 796 |
+
# fn=add_translated_subtitles_to_video,
|
| 797 |
+
# inputs=[original_video_path, original_audio_path, original_audio_translated_path],
|
| 798 |
+
# outputs=[subtitled_video, video_subtitled_progress_info, auxiliar_block3]
|
| 799 |
+
# )
|
| 800 |
+
# auxiliar_block3.change(
|
| 801 |
+
# fn=hide_textbobes_progress_info,
|
| 802 |
+
# outputs=[video_donwloaded_progress_info, video_sliced_progress_info, video_transcribed_progress_info, transcriptions_concatenated_progress_info, video_translated_progress_info, video_subtitled_progress_info]
|
| 803 |
+
# )
|
| 804 |
+
|
| 805 |
+
# gr.HTML(html_buy_me_a_coffe)
|
| 806 |
|
| 807 |
demo.launch()
|
| 808 |
|