Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- webui/app.py +841 -816
- webui/library.py +4 -4
webui/app.py
CHANGED
|
@@ -1,816 +1,841 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import subprocess
|
| 3 |
-
import os
|
| 4 |
-
import sys
|
| 5 |
-
import json
|
| 6 |
-
import psutil
|
| 7 |
-
import
|
| 8 |
-
import
|
| 9 |
-
import
|
| 10 |
-
|
| 11 |
-
from fastapi
|
| 12 |
-
import
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
import
|
| 17 |
-
import
|
| 18 |
-
import
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
i18n
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
"
|
| 39 |
-
"Active Speaker (
|
| 40 |
-
"Active Speaker (
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
'gemini-
|
| 85 |
-
'gemini-2.5-flash
|
| 86 |
-
'gemini-2.5-flash-
|
| 87 |
-
'gemini-2.5-flash-lite
|
| 88 |
-
'gemini-2.5-
|
| 89 |
-
'gemini-2.
|
| 90 |
-
'gemini-2.0-flash
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
'gpt-4o
|
| 96 |
-
'gpt-
|
| 97 |
-
'
|
| 98 |
-
'o1',
|
| 99 |
-
'
|
| 100 |
-
'deepseek-
|
| 101 |
-
'
|
| 102 |
-
'llama-3.
|
| 103 |
-
'
|
| 104 |
-
'claude-3.
|
| 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 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
if
|
| 182 |
-
if
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
if
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
if
|
| 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 |
-
if
|
| 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 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 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 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 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 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
)
|
| 562 |
-
|
| 563 |
-
with gr.
|
| 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 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 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 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
print(
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
gr.set_static_paths
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
#
|
| 774 |
-
app =
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import json
|
| 6 |
+
import psutil
|
| 7 |
+
import shutil
|
| 8 |
+
import datetime
|
| 9 |
+
import time
|
| 10 |
+
import urllib.parse
|
| 11 |
+
from fastapi import FastAPI
|
| 12 |
+
from fastapi.staticfiles import StaticFiles
|
| 13 |
+
import uvicorn
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
import re
|
| 17 |
+
import library # Module for Library Logic
|
| 18 |
+
import subtitle_handler as subs # Module for Subtitles
|
| 19 |
+
import subtitle_editor as editor # Module for Editor Logic
|
| 20 |
+
|
| 21 |
+
# Path to the main script
|
| 22 |
+
MAIN_SCRIPT_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "main_improved.py")
|
| 23 |
+
WORKING_DIR = os.path.dirname(MAIN_SCRIPT_PATH)
|
| 24 |
+
sys.path.append(WORKING_DIR)
|
| 25 |
+
|
| 26 |
+
from i18n.i18n import I18nAuto
|
| 27 |
+
i18n = I18nAuto()
|
| 28 |
+
|
| 29 |
+
# --- PRESETS DEFINITIONS ---
|
| 30 |
+
FACE_PRESETS = {
|
| 31 |
+
"Default (Balanced)": {"thresh": 0.35, "two_face": 0.60, "conf": 0.40, "dead_zone": 150},
|
| 32 |
+
"Stable (Focus Main)": {"thresh": 0.60, "two_face": 0.80, "conf": 0.60, "dead_zone": 200},
|
| 33 |
+
"Sensitive (Catch All)": {"thresh": 0.10, "two_face": 0.40, "conf": 0.30, "dead_zone": 100},
|
| 34 |
+
"High Precision": {"thresh": 0.40, "two_face": 0.65, "conf": 0.75, "dead_zone": 150},
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
EXPERIMENTAL_PRESETS = {
|
| 38 |
+
"Default (Off)": {"focus": False, "mar": 0.03, "score": 1.5, "motion": False, "motion_th": 3.0, "motion_sens": 0.05, "decay": 2.0},
|
| 39 |
+
"Active Speaker (Balanced)": {"focus": True, "mar": 0.03, "score": 1.5, "motion": True, "motion_th": 3.0, "motion_sens": 0.05, "decay": 2.0},
|
| 40 |
+
"Active Speaker (Sensitive)": {"focus": True, "mar": 0.02, "score": 1.0, "motion": True, "motion_th": 2.0, "motion_sens": 0.10, "decay": 1.0},
|
| 41 |
+
"Active Speaker (Stable)": {"focus": True, "mar": 0.05, "score": 2.5, "motion": False, "motion_th": 5.0, "motion_sens": 0.02, "decay": 3.0},
|
| 42 |
+
}
|
| 43 |
+
# ---------------------------
|
| 44 |
+
|
| 45 |
+
VIRALS_DIR = os.path.join(WORKING_DIR, "VIRALS")
|
| 46 |
+
MODELS_DIR = os.path.join(WORKING_DIR, "models")
|
| 47 |
+
|
| 48 |
+
# Ensure directories exist
|
| 49 |
+
if not os.path.exists(VIRALS_DIR):
|
| 50 |
+
os.makedirs(VIRALS_DIR, exist_ok=True)
|
| 51 |
+
if not os.path.exists(MODELS_DIR):
|
| 52 |
+
os.makedirs(MODELS_DIR, exist_ok=True)
|
| 53 |
+
|
| 54 |
+
# Global variables
|
| 55 |
+
current_process = None
|
| 56 |
+
|
| 57 |
+
# Helpers
|
| 58 |
+
def convert_color_to_ass(hex_color, alpha="00"):
|
| 59 |
+
if not hex_color or not hex_color.startswith("#"):
|
| 60 |
+
return f"&H{alpha}FFFFFF&"
|
| 61 |
+
hex_clean = hex_color.lstrip('#')
|
| 62 |
+
if len(hex_clean) == 6:
|
| 63 |
+
r = hex_clean[0:2]
|
| 64 |
+
g = hex_clean[2:4]
|
| 65 |
+
b = hex_clean[4:6]
|
| 66 |
+
return f"&H{alpha}{b}{g}{r}&"
|
| 67 |
+
return f"&H{alpha}FFFFFF&"
|
| 68 |
+
|
| 69 |
+
def kill_process():
|
| 70 |
+
global current_process
|
| 71 |
+
if current_process:
|
| 72 |
+
try:
|
| 73 |
+
parent = psutil.Process(current_process.pid)
|
| 74 |
+
for child in parent.children(recursive=True):
|
| 75 |
+
child.kill()
|
| 76 |
+
parent.kill()
|
| 77 |
+
current_process = None
|
| 78 |
+
return i18n("Process terminated.")
|
| 79 |
+
except Exception as e:
|
| 80 |
+
return i18n("Error terminating process: {}").format(e)
|
| 81 |
+
return i18n("No process running.")
|
| 82 |
+
|
| 83 |
+
GEMINI_MODELS = [
|
| 84 |
+
'gemini-3-pro-preview',
|
| 85 |
+
'gemini-2.5-flash',
|
| 86 |
+
'gemini-2.5-flash-preview-09-2025',
|
| 87 |
+
'gemini-2.5-flash-lite',
|
| 88 |
+
'gemini-2.5-flash-lite-preview-09-2025',
|
| 89 |
+
'gemini-2.5-pro',
|
| 90 |
+
'gemini-2.0-flash',
|
| 91 |
+
'gemini-2.0-flash-lite'
|
| 92 |
+
]
|
| 93 |
+
|
| 94 |
+
G4F_MODELS = [
|
| 95 |
+
'gpt-4o',
|
| 96 |
+
'gpt-4o-mini',
|
| 97 |
+
'gpt-4',
|
| 98 |
+
'o1-mini',
|
| 99 |
+
'o1',
|
| 100 |
+
'deepseek-r1',
|
| 101 |
+
'deepseek-v3',
|
| 102 |
+
'llama-3.3-70b',
|
| 103 |
+
'llama-3.1-405b',
|
| 104 |
+
'claude-3.5-sonnet',
|
| 105 |
+
'claude-3.7-sonnet',
|
| 106 |
+
'gemini-2.0-flash',
|
| 107 |
+
'qwen-2.5-72b'
|
| 108 |
+
]
|
| 109 |
+
|
| 110 |
+
def get_local_models():
|
| 111 |
+
if not os.path.exists(MODELS_DIR): return []
|
| 112 |
+
return [f for f in os.listdir(MODELS_DIR) if f.endswith(".gguf")]
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def apply_face_preset(preset_name):
|
| 117 |
+
if preset_name not in FACE_PRESETS:
|
| 118 |
+
return [gr.update() for _ in range(4)] # No change
|
| 119 |
+
|
| 120 |
+
p = FACE_PRESETS[preset_name]
|
| 121 |
+
return p["thresh"], p["two_face"], p["conf"], p["dead_zone"]
|
| 122 |
+
|
| 123 |
+
def apply_experimental_preset(preset_name):
|
| 124 |
+
if preset_name not in EXPERIMENTAL_PRESETS:
|
| 125 |
+
return [gr.update() for _ in range(7)] # No change
|
| 126 |
+
|
| 127 |
+
p = EXPERIMENTAL_PRESETS[preset_name]
|
| 128 |
+
return p["focus"], p["mar"], p["score"], p["motion"], p["motion_th"], p["motion_sens"], p["decay"]
|
| 129 |
+
|
| 130 |
+
# Subtitle logic moved to subtitle_handler.py
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def run_viral_cutter(input_source, project_name, url, video_file, segments, viral, themes, min_duration, max_duration, model, ai_backend, api_key, ai_model_name, chunk_size, workflow, face_model, face_mode, face_detect_interval,
|
| 134 |
+
face_filter_thresh, face_two_thresh, face_conf_thresh, face_dead_zone, focus_active_speaker, active_speaker_mar, active_speaker_score_diff, include_motion, active_speaker_motion_threshold, active_speaker_motion_sensitivity, active_speaker_decay,
|
| 135 |
+
use_custom_subs, font_name, font_size, font_color, highlight_color, outline_color, outline_thickness, shadow_color, shadow_size, is_bold, is_italic, is_uppercase, vertical_pos, alignment,
|
| 136 |
+
h_size, w_block, gap, mode, under, strike, border_s, remove_punc, video_quality, use_youtube_subs, translate_target):
|
| 137 |
+
|
| 138 |
+
global current_process
|
| 139 |
+
yield "", gr.update(value=i18n("Running..."), interactive=False), gr.update(visible=True), None
|
| 140 |
+
|
| 141 |
+
cmd = [sys.executable, MAIN_SCRIPT_PATH]
|
| 142 |
+
|
| 143 |
+
# Input Source Logic
|
| 144 |
+
if input_source == "Existing Project":
|
| 145 |
+
if not project_name:
|
| 146 |
+
yield i18n("Error: No project selected."), gr.update(value=i18n("Start Processing"), interactive=True), gr.update(visible=False), None
|
| 147 |
+
return
|
| 148 |
+
full_project_path = os.path.join(VIRALS_DIR, project_name)
|
| 149 |
+
cmd.extend(["--project-path", full_project_path])
|
| 150 |
+
elif input_source == "Upload Video":
|
| 151 |
+
if not video_file:
|
| 152 |
+
yield i18n("Error: No video file uploaded."), gr.update(value=i18n("Start Processing"), interactive=True), gr.update(visible=False), None
|
| 153 |
+
return
|
| 154 |
+
|
| 155 |
+
# Create new project for upload
|
| 156 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 157 |
+
project_name_upload = f"Upload_{timestamp}"
|
| 158 |
+
project_path = os.path.join(VIRALS_DIR, project_name_upload)
|
| 159 |
+
os.makedirs(project_path, exist_ok=True)
|
| 160 |
+
|
| 161 |
+
target_path = os.path.join(project_path, "input.mp4")
|
| 162 |
+
shutil.copy(video_file, target_path)
|
| 163 |
+
|
| 164 |
+
cmd.extend(["--project-path", project_path])
|
| 165 |
+
# Skip YouTube subs as it is a local upload
|
| 166 |
+
cmd.append("--skip-youtube-subs")
|
| 167 |
+
|
| 168 |
+
else:
|
| 169 |
+
if url: cmd.extend(["--url", url])
|
| 170 |
+
# Pass Video Quality
|
| 171 |
+
if video_quality: cmd.extend(["--video-quality", video_quality])
|
| 172 |
+
# Pass Subtitle Option (if False, we skip)
|
| 173 |
+
if not use_youtube_subs: cmd.append("--skip-youtube-subs")
|
| 174 |
+
|
| 175 |
+
# Translation
|
| 176 |
+
if translate_target and translate_target != "None":
|
| 177 |
+
cmd.extend(["--translate-target", translate_target])
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
cmd.extend(["--segments", str(int(segments))])
|
| 181 |
+
if viral: cmd.append("--viral")
|
| 182 |
+
if themes: cmd.extend(["--themes", themes])
|
| 183 |
+
cmd.extend(["--min-duration", str(int(min_duration))])
|
| 184 |
+
cmd.extend(["--max-duration", str(int(max_duration))])
|
| 185 |
+
cmd.extend(["--model", model])
|
| 186 |
+
cmd.extend(["--ai-backend", ai_backend])
|
| 187 |
+
if api_key: cmd.extend(["--api-key", api_key])
|
| 188 |
+
|
| 189 |
+
# New AI Params
|
| 190 |
+
if ai_model_name: cmd.extend(["--ai-model-name", str(ai_model_name)])
|
| 191 |
+
if chunk_size: cmd.extend(["--chunk-size", str(int(chunk_size))])
|
| 192 |
+
|
| 193 |
+
workflow_map = {"Full": "1", "Cut Only": "2", "Subtitles Only": "3"}
|
| 194 |
+
cmd.extend(["--workflow", workflow_map.get(workflow, "1")])
|
| 195 |
+
cmd.extend(["--face-model", face_model])
|
| 196 |
+
cmd.extend(["--face-mode", face_mode])
|
| 197 |
+
if face_detect_interval: cmd.extend(["--face-detect-interval", str(face_detect_interval)])
|
| 198 |
+
|
| 199 |
+
# New Face Params
|
| 200 |
+
if face_filter_thresh is not None: cmd.extend(["--face-filter-threshold", str(face_filter_thresh)])
|
| 201 |
+
if face_two_thresh is not None: cmd.extend(["--face-two-threshold", str(face_two_thresh)])
|
| 202 |
+
if face_conf_thresh is not None: cmd.extend(["--face-confidence-threshold", str(face_conf_thresh)])
|
| 203 |
+
if face_dead_zone is not None: cmd.extend(["--face-dead-zone", str(face_dead_zone)])
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
cmd.append("--skip-prompts")
|
| 208 |
+
|
| 209 |
+
if focus_active_speaker:
|
| 210 |
+
cmd.append("--focus-active-speaker")
|
| 211 |
+
if active_speaker_mar is not None: cmd.extend(["--active-speaker-mar", str(active_speaker_mar)])
|
| 212 |
+
if active_speaker_score_diff is not None: cmd.extend(["--active-speaker-score-diff", str(active_speaker_score_diff)])
|
| 213 |
+
if include_motion: cmd.append("--include-motion")
|
| 214 |
+
if active_speaker_motion_threshold is not None: cmd.extend(["--active-speaker-motion-threshold", str(active_speaker_motion_threshold)])
|
| 215 |
+
if active_speaker_motion_sensitivity is not None: cmd.extend(["--active-speaker-motion-sensitivity", str(active_speaker_motion_sensitivity)])
|
| 216 |
+
if active_speaker_decay is not None: cmd.extend(["--active-speaker-decay", str(active_speaker_decay)])
|
| 217 |
+
|
| 218 |
+
cmd.append("--skip-prompts") # Always skip prompts in WebUI to prevent freezing
|
| 219 |
+
|
| 220 |
+
if use_custom_subs:
|
| 221 |
+
subtitle_config = {
|
| 222 |
+
"font": font_name, "base_size": int(font_size), "base_color": convert_color_to_ass(font_color), "highlight_color": convert_color_to_ass(highlight_color),
|
| 223 |
+
"outline_color": convert_color_to_ass(outline_color), "outline_thickness": outline_thickness, "shadow_color": convert_color_to_ass(shadow_color),
|
| 224 |
+
"shadow_size": shadow_size, "vertical_position": vertical_pos, "alignment": alignment, "bold": 1 if is_bold else 0, "italic": 1 if is_italic else 0,
|
| 225 |
+
"underline": 1 if under else 0, "strikeout": 1 if strike else 0, "border_style": border_s, "words_per_block": int(w_block), "gap_limit": gap,
|
| 226 |
+
"mode": mode, "highlight_size": int(h_size), "remove_punctuation": remove_punc
|
| 227 |
+
}
|
| 228 |
+
# Uppercase is handled in main script or logic?
|
| 229 |
+
# Actually subtitle_config doesn't seem to natively support "uppercase" in get_subtitle_config default, but app.py was using it.
|
| 230 |
+
# I should probably add it back if I want to support it, but user said "PROHIBITED to remove existing ones".
|
| 231 |
+
# I'll re-add 'uppercase': 1 if is_uppercase else 0 to the dict if the backend supports it, otherwise it's just ignored.
|
| 232 |
+
# But wait, main_improved.py doesn't have 'uppercase' in get_subtitle_config.
|
| 233 |
+
# I'll keep it in the dict just in case logic uses it elsewhere or if I missed it.
|
| 234 |
+
# Actually, standard ASS doesn't support uppercase flag directly in Style, it needs to be text transform.
|
| 235 |
+
# But I'll leave it in the dict.
|
| 236 |
+
subtitle_config["uppercase"] = 1 if is_uppercase else 0
|
| 237 |
+
|
| 238 |
+
subtitle_config_path = os.path.join(WORKING_DIR, "temp_subtitle_config.json")
|
| 239 |
+
try:
|
| 240 |
+
with open(subtitle_config_path, "w", encoding="utf-8") as f:
|
| 241 |
+
json.dump(subtitle_config, f, indent=4)
|
| 242 |
+
cmd.extend(["--subtitle-config", subtitle_config_path])
|
| 243 |
+
except Exception: pass
|
| 244 |
+
|
| 245 |
+
env = os.environ.copy()
|
| 246 |
+
env["PYTHONUNBUFFERED"] = "1"
|
| 247 |
+
try:
|
| 248 |
+
current_process = subprocess.Popen(cmd, cwd=WORKING_DIR, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, universal_newlines=True, env=env)
|
| 249 |
+
logs = ""
|
| 250 |
+
project_folder_path = None
|
| 251 |
+
if input_source == "Existing Project" and project_name:
|
| 252 |
+
# If using existing project, we already know the path, but let's see if logs confirm it
|
| 253 |
+
project_folder_path = os.path.join(VIRALS_DIR, project_name)
|
| 254 |
+
|
| 255 |
+
while True:
|
| 256 |
+
line = current_process.stdout.readline()
|
| 257 |
+
if not line and current_process.poll() is not None:
|
| 258 |
+
break
|
| 259 |
+
|
| 260 |
+
if line:
|
| 261 |
+
logs += line
|
| 262 |
+
if "Project Folder:" in line:
|
| 263 |
+
parts = line.split("Project Folder:")
|
| 264 |
+
if len(parts) > 1: project_folder_path = parts[1].strip()
|
| 265 |
+
yield logs, gr.update(visible=True, interactive=False), gr.update(visible=True), None
|
| 266 |
+
except Exception as e:
|
| 267 |
+
logs += f"\nError running process: {str(e)}\n"
|
| 268 |
+
yield logs, gr.update(visible=True, interactive=False), gr.update(visible=True), None
|
| 269 |
+
finally:
|
| 270 |
+
if current_process:
|
| 271 |
+
if current_process.stdout:
|
| 272 |
+
try:
|
| 273 |
+
current_process.stdout.close()
|
| 274 |
+
except Exception: pass
|
| 275 |
+
if current_process.poll() is None:
|
| 276 |
+
# If we are here, it means we finished reading or errored out, but process is still running.
|
| 277 |
+
# If it was a normal break from loop, process should be done or close to done.
|
| 278 |
+
# If we are stopping, current_process.terminate() might be needed outside?
|
| 279 |
+
# But here we just wait.
|
| 280 |
+
try:
|
| 281 |
+
current_process.wait()
|
| 282 |
+
except Exception: pass
|
| 283 |
+
current_process = None
|
| 284 |
+
|
| 285 |
+
# Wait to ensure filesystem flush
|
| 286 |
+
time.sleep(1.0)
|
| 287 |
+
|
| 288 |
+
html_output = ""
|
| 289 |
+
if project_folder_path and os.path.exists(project_folder_path):
|
| 290 |
+
html_output = library.generate_project_gallery(project_folder_path, is_full_path=True)
|
| 291 |
+
else:
|
| 292 |
+
html_output = f"<h3>{i18n('Error: Project folder could not be determined from logs.')}</h3>"
|
| 293 |
+
yield logs, gr.update(value=i18n("Start Processing"), interactive=True), gr.update(visible=False), html_output
|
| 294 |
+
|
| 295 |
+
css = """
|
| 296 |
+
/* Global Dark Theme Overrides */
|
| 297 |
+
body, .gradio-container {
|
| 298 |
+
background-color: #0b0b0b !important;
|
| 299 |
+
color: #ffffff !important;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
/* Force dark background for specific inputs that might be white */
|
| 303 |
+
input[type="password"], textarea, select {
|
| 304 |
+
background-color: #1f1f1f !important;
|
| 305 |
+
color: #ffffff !important;
|
| 306 |
+
border: 1px solid #333 !important;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
/* Hide Footer */
|
| 310 |
+
footer {visibility: hidden}
|
| 311 |
+
|
| 312 |
+
/* Container Width */
|
| 313 |
+
.gradio-container {
|
| 314 |
+
max-width: 98% !important;
|
| 315 |
+
width: 98% !important;
|
| 316 |
+
margin: 0 auto !important;
|
| 317 |
+
}
|
| 318 |
+
"""
|
| 319 |
+
|
| 320 |
+
import header
|
| 321 |
+
|
| 322 |
+
with gr.Blocks(title=i18n("ViralCutter WebUI"), theme=gr.themes.Default(primary_hue="orange", neutral_hue="slate"), css=css) as demo:
|
| 323 |
+
gr.Markdown(header.badges)
|
| 324 |
+
gr.Markdown(header.description)
|
| 325 |
+
with gr.Tabs():
|
| 326 |
+
with gr.Tab(i18n("Create New")):
|
| 327 |
+
with gr.Row():
|
| 328 |
+
with gr.Column(scale=1):
|
| 329 |
+
input_source = gr.Radio([(i18n("YouTube URL"), "YouTube URL"), (i18n("Existing Project"), "Existing Project"), (i18n("Upload Video"), "Upload Video")], label=i18n("Input Source"), value="YouTube URL")
|
| 330 |
+
|
| 331 |
+
url_input = gr.Textbox(label=i18n("YouTube URL"), placeholder="https://www.youtube.com/watch?v=...", visible=True)
|
| 332 |
+
video_upload = gr.File(label=i18n("Upload Video"), file_count="single", file_types=["video"], visible=False)
|
| 333 |
+
|
| 334 |
+
with gr.Row():
|
| 335 |
+
video_quality_input = gr.Dropdown(choices=["best", "1080p", "720p", "480p"], label=i18n("Video Quality"), value="best")
|
| 336 |
+
translate_input = gr.Dropdown(choices=["None", "pt", "en", "es", "fr", "de", "it", "ru", "ja", "ko", "zh-CN"], label=i18n("Translate Subtitles To"), value="None")
|
| 337 |
+
use_youtube_subs_input = gr.Checkbox(label=i18n("Use YouTube Subs"), value=True, info=i18n("Download and use official subtitles if available. (Recommended, it speeds up the process)"))
|
| 338 |
+
|
| 339 |
+
project_selector = gr.Dropdown(choices=[], label=i18n("Select Project"), visible=False)
|
| 340 |
+
|
| 341 |
+
def on_source_change(source):
|
| 342 |
+
if source == "YouTube URL":
|
| 343 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(value="Full")
|
| 344 |
+
elif source == "Upload Video":
|
| 345 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(value="Full")
|
| 346 |
+
else:
|
| 347 |
+
# Load projects
|
| 348 |
+
projs = library.get_existing_projects()
|
| 349 |
+
return gr.update(visible=False), gr.update(choices=projs, visible=True), gr.update(visible=False), gr.update(value="Subtitles Only")
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
with gr.Row():
|
| 353 |
+
segments_input = gr.Number(label=i18n("Segments"), value=3, precision=0)
|
| 354 |
+
viral_input = gr.Checkbox(label=i18n("Viral Mode"), value=True)
|
| 355 |
+
themes_input = gr.Textbox(label=i18n("Themes"), placeholder=i18n("funny, sad..."), visible=False)
|
| 356 |
+
viral_input.change(lambda x: gr.update(visible=not x), viral_input, themes_input)
|
| 357 |
+
with gr.Row():
|
| 358 |
+
min_dur_input = gr.Number(label=i18n("Min Duration (s)"), value=15)
|
| 359 |
+
max_dur_input = gr.Number(label=i18n("Max Duration (s)"), value=90)
|
| 360 |
+
with gr.Column(scale=1):
|
| 361 |
+
with gr.Row():
|
| 362 |
+
ai_backend_input = gr.Dropdown(choices=[(i18n("Gemini"), "gemini"), (i18n("G4F"), "g4f"), (i18n("Local (GGUF)"), "local"), (i18n("Manual"), "manual")], label=i18n("AI Backend"), value="gemini", scale=2)
|
| 363 |
+
api_key_input = gr.Textbox(label=i18n("Gemini API Key"), type="password", scale=3)
|
| 364 |
+
|
| 365 |
+
# New Dynamic Inputs
|
| 366 |
+
with gr.Row():
|
| 367 |
+
ai_model_input = gr.Dropdown(choices=GEMINI_MODELS, label=i18n("AI Model"), value=GEMINI_MODELS[1], allow_custom_value=True, visible=True, scale=5)
|
| 368 |
+
refresh_models_btn = gr.Button("🔄", size="sm", visible=False, scale=0, min_width=50) # Only local
|
| 369 |
+
chunk_size_input = gr.Number(label=i18n("Chunk Size"), value=20000, precision=0, scale=2)
|
| 370 |
+
|
| 371 |
+
# Update listeners with logic to hide/show API key
|
| 372 |
+
def update_ai_ui(backend):
|
| 373 |
+
show_api = (backend == "gemini")
|
| 374 |
+
show_refresh = (backend == "local")
|
| 375 |
+
|
| 376 |
+
# Definições padrão para evitar que fiquem vazios
|
| 377 |
+
new_choices = []
|
| 378 |
+
new_val = ""
|
| 379 |
+
new_chunk = 20000
|
| 380 |
+
|
| 381 |
+
if backend == "gemini":
|
| 382 |
+
new_choices = GEMINI_MODELS
|
| 383 |
+
new_val = GEMINI_MODELS[1]
|
| 384 |
+
new_chunk = 20000
|
| 385 |
+
elif backend == "g4f":
|
| 386 |
+
new_choices = G4F_MODELS
|
| 387 |
+
new_val = G4F_MODELS[0]
|
| 388 |
+
new_chunk = 3000
|
| 389 |
+
elif backend == "local":
|
| 390 |
+
models = get_local_models()
|
| 391 |
+
new_choices = models if models else [i18n("No models found")]
|
| 392 |
+
new_val = new_choices[0]
|
| 393 |
+
new_chunk = 15000
|
| 394 |
+
else: # Manual
|
| 395 |
+
pass
|
| 396 |
+
|
| 397 |
+
return (
|
| 398 |
+
gr.update(visible=show_api), # API Key Visibility (Fixes hole 1)
|
| 399 |
+
gr.update(choices=new_choices, value=new_val, visible=(backend != "manual")), # Model Dropdown
|
| 400 |
+
gr.update(visible=show_refresh), # Refresh Button
|
| 401 |
+
gr.update(value=new_chunk) # Chunk Size
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
def refresh_local_models():
|
| 405 |
+
models = get_local_models()
|
| 406 |
+
val = models[0] if models else i18n("No models found")
|
| 407 |
+
return gr.update(choices=models, value=val)
|
| 408 |
+
|
| 409 |
+
refresh_models_btn.click(refresh_local_models, outputs=ai_model_input)
|
| 410 |
+
ai_backend_input.change(update_ai_ui, inputs=ai_backend_input, outputs=[api_key_input, ai_model_input, refresh_models_btn, chunk_size_input])
|
| 411 |
+
|
| 412 |
+
model_input = gr.Dropdown(["tiny", "small", "medium", "large", "large-v1", "large-v2", "large-v3", "turbo", "large-v3-turbo", "distil-large-v2", "distil-medium.en", "distil-small.en", "distil-large-v3"], label=i18n("Whisper Model"), value="large-v3-turbo")
|
| 413 |
+
with gr.Row():
|
| 414 |
+
workflow_input = gr.Dropdown(choices=[(i18n("Full"), "Full"), (i18n("Cut Only"), "Cut Only"), (i18n("Subtitles Only"), "Subtitles Only")], label=i18n("Workflow"), value="Full")
|
| 415 |
+
face_model_input = gr.Dropdown(["insightface", "mediapipe"], label=i18n("Face Model"), value="insightface")
|
| 416 |
+
with gr.Row():
|
| 417 |
+
face_mode_input = gr.Dropdown(choices=[(i18n("Auto"), "auto"), ("1", "1"), ("2", "2")], label=i18n("Face Mode"), value="auto")
|
| 418 |
+
face_detect_interval_input = gr.Textbox(label=i18n("Face Det. Interval"), value="0.17,1.0")
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
# Update listeners now that all components are defined
|
| 422 |
+
input_source.change(on_source_change, inputs=input_source, outputs=[url_input, project_selector, video_upload, workflow_input])
|
| 423 |
+
|
| 424 |
+
with gr.Accordion(i18n("Advanced Face Settings"), open=False):
|
| 425 |
+
face_preset_input = gr.Dropdown(choices=[(i18n(k), k) for k in FACE_PRESETS.keys()], label=i18n("Configuration Presets"), value="Default (Balanced)", interactive=True)
|
| 426 |
+
with gr.Row():
|
| 427 |
+
face_filter_thresh_input = gr.Slider(label=i18n("Ignore Small Faces (0.0 - 1.0)"), minimum=0.0, maximum=1.0, value=0.35, step=0.05, info=i18n("Relative size to ignore background."))
|
| 428 |
+
face_two_thresh_input = gr.Slider(label=i18n("Threshold for 2 Faces (0.0 - 1.0)"), minimum=0.0, maximum=1.0, value=0.60, step=0.05, info=i18n("Size of 2nd face to activate split mode."))
|
| 429 |
+
face_conf_thresh_input = gr.Slider(label=i18n("Minimum Confidence (0.0 - 1.0)"), minimum=0.0, maximum=1.0, value=0.40, step=0.05, info=i18n("Ignore detections with low confidence."))
|
| 430 |
+
face_dead_zone_input = gr.Slider(label=i18n("Dead Zone (Stabilization)"), minimum=0, maximum=200, value=150, step=5, info=i18n("Movement pixels to ignore."))
|
| 431 |
+
|
| 432 |
+
face_preset_input.change(apply_face_preset, inputs=face_preset_input, outputs=[face_filter_thresh_input, face_two_thresh_input, face_conf_thresh_input, face_dead_zone_input])
|
| 433 |
+
|
| 434 |
+
with gr.Accordion(i18n("Experimental: Active Speaker & Motion"), open=False):
|
| 435 |
+
experimental_preset_input = gr.Dropdown(choices=[(i18n(k), k) for k in EXPERIMENTAL_PRESETS.keys()], label=i18n("Configuration Presets"), value="Default (Off)", interactive=True)
|
| 436 |
+
focus_active_speaker_input = gr.Checkbox(label=i18n("Experimental: Focus on Speaker"), value=False, info=i18n("Tries to focus only on the speaking person instead of split screen."))
|
| 437 |
+
with gr.Row():
|
| 438 |
+
active_speaker_mar_input = gr.Slider(label=i18n("MAR Threshold (Mouth Open)"), minimum=0.01, maximum=0.20, value=0.03, step=0.005, info=i18n("Mouth open sensitivity."))
|
| 439 |
+
active_speaker_score_diff_input = gr.Slider(label=i18n("Score Difference"), minimum=0.5, maximum=10.0, value=1.5, step=0.5, info=i18n("Minimum difference to focus on 1 face."))
|
| 440 |
+
|
| 441 |
+
with gr.Row():
|
| 442 |
+
include_motion_input = gr.Checkbox(label=i18n("Consider Motion"), value=False, info=i18n("Increases score with motion (gestures)."))
|
| 443 |
+
|
| 444 |
+
with gr.Row():
|
| 445 |
+
active_speaker_motion_threshold_input = gr.Slider(label=i18n("Motion Dead Zone"), minimum=0.0, maximum=20.0, value=3.0, step=0.5, info=i18n("Pixels ignored."))
|
| 446 |
+
active_speaker_motion_sensitivity_input = gr.Slider(label=i18n("Motion Sensitivity"), minimum=0.01, maximum=0.5, value=0.05, step=0.01, info=i18n("Points per pixel."))
|
| 447 |
+
active_speaker_decay_input = gr.Slider(label=i18n("Switch Speed"), minimum=0.5, maximum=5.0, value=2.0, step=0.5, info=i18n("Speed to lose focus."))
|
| 448 |
+
|
| 449 |
+
experimental_preset_input.change(apply_experimental_preset, inputs=experimental_preset_input, outputs=[focus_active_speaker_input, active_speaker_mar_input, active_speaker_score_diff_input, include_motion_input, active_speaker_motion_threshold_input, active_speaker_motion_sensitivity_input, active_speaker_decay_input])
|
| 450 |
+
with gr.Accordion(i18n("Subtitle Settings (alpha)"), open=False):
|
| 451 |
+
preset_input = gr.Dropdown(choices=[(i18n("Manual"), "Manual")] + [(i18n(k), k) for k in subs.SUBTITLE_PRESETS.keys()], label=i18n("Quick Presets"), value="Hormozi (Classic)")
|
| 452 |
+
use_custom_subs = gr.Checkbox(label=i18n("Enable Subtitle Customization (Includes Preset)"), value=True)
|
| 453 |
+
|
| 454 |
+
# Previews (Always Visible)
|
| 455 |
+
preview_html = gr.HTML(value=f"<div style='text-align:center; padding:10px; color:#666;'>{i18n('Select options or preset to preview')}</div>")
|
| 456 |
+
|
| 457 |
+
with gr.Row():
|
| 458 |
+
preview_vid_btn = gr.Button(i18n("🎬 Render Animated Preview (Slow)"), size="sm")
|
| 459 |
+
preview_vid = gr.Video(label=i18n("Animated Preview"), height=300, autoplay=True, interactive=False)
|
| 460 |
+
|
| 461 |
+
with gr.Accordion(i18n("Advanced Settings"), open=False):
|
| 462 |
+
gr.Markdown(f"### {i18n('Appearance')}")
|
| 463 |
+
with gr.Row():
|
| 464 |
+
font_name_input = gr.Textbox(label=i18n("Font Name"), value="Montserrat-Regular")
|
| 465 |
+
font_size_input = gr.Slider(label=i18n("Font Size (Base)"), minimum=8, maximum=80, value=12)
|
| 466 |
+
highlight_size_input = gr.Slider(label=i18n("Highlight Size"), minimum=8, maximum=80, value=14)
|
| 467 |
+
|
| 468 |
+
with gr.Row():
|
| 469 |
+
font_color_input = gr.ColorPicker(label=i18n("Base Color"), value="#FFFFFF")
|
| 470 |
+
highlight_color_input = gr.ColorPicker(label=i18n("Highlight Color"), value="#00FF00")
|
| 471 |
+
outline_color_input = gr.ColorPicker(label=i18n("Outline Color"), value="#000000")
|
| 472 |
+
shadow_color_input = gr.ColorPicker(label=i18n("Shadow Color"), value="#000000")
|
| 473 |
+
|
| 474 |
+
gr.Markdown(f"### {i18n('Styling & Effects')}")
|
| 475 |
+
with gr.Row():
|
| 476 |
+
outline_thickness_input = gr.Slider(label=i18n("Outline Thickness"), minimum=0, maximum=10, value=1.5)
|
| 477 |
+
shadow_size_input = gr.Slider(label=i18n("Shadow Size"), minimum=0, maximum=10, value=2)
|
| 478 |
+
border_style_input = gr.Dropdown(choices=[(i18n("Outline"), 1), (i18n("Opaque Box"), 3)], label=i18n("Border Style"), value=1)
|
| 479 |
+
|
| 480 |
+
with gr.Row():
|
| 481 |
+
bold_input = gr.Checkbox(label=i18n("Bold"))
|
| 482 |
+
italic_input = gr.Checkbox(label=i18n("Italic"))
|
| 483 |
+
uppercase_input = gr.Checkbox(label=i18n("Uppercase"))
|
| 484 |
+
remove_punc_input = gr.Checkbox(label=i18n("Remove Punctuation"), value=True)
|
| 485 |
+
underline_input = gr.Checkbox(label=i18n("Underline"))
|
| 486 |
+
strikeout_input = gr.Checkbox(label=i18n("Strikeout"))
|
| 487 |
+
|
| 488 |
+
gr.Markdown(f"### {i18n('Positioning & Layout')}")
|
| 489 |
+
with gr.Row():
|
| 490 |
+
vertical_pos_input = gr.Slider(label=i18n("V-Pos (Margin V)"), minimum=0, maximum=500, value=210)
|
| 491 |
+
alignment_input = gr.Dropdown(choices=[(i18n("Left"), 1), (i18n("Center"), 2), (i18n("Right"), 3)], label=i18n("Alignment"), value=2)
|
| 492 |
+
gap_limit_input = gr.Slider(label=i18n("Gap Limit"), minimum=0.0, maximum=5.0, value=0.5, step=0.1)
|
| 493 |
+
mode_input = gr.Dropdown(choices=[(i18n("Highlight"), "highlight"), (i18n("Word by Word"), "word_by_word"), (i18n("No Highlight"), "no_highlight")], label=i18n("Mode"), value="highlight")
|
| 494 |
+
words_per_block_input = gr.Slider(label=i18n("Words per Block"), minimum=1, maximum=20, value=3, step=1)
|
| 495 |
+
|
| 496 |
+
manual_inputs = [
|
| 497 |
+
font_name_input, font_size_input, font_color_input, highlight_color_input,
|
| 498 |
+
outline_color_input, outline_thickness_input, shadow_color_input, shadow_size_input,
|
| 499 |
+
bold_input, italic_input, uppercase_input,
|
| 500 |
+
highlight_size_input, words_per_block_input, gap_limit_input, mode_input,
|
| 501 |
+
underline_input, strikeout_input, border_style_input,
|
| 502 |
+
vertical_pos_input, alignment_input,
|
| 503 |
+
remove_punc_input
|
| 504 |
+
]
|
| 505 |
+
|
| 506 |
+
# Update manual inputs when preset changes
|
| 507 |
+
preset_input.change(subs.apply_preset, inputs=[preset_input], outputs=manual_inputs)
|
| 508 |
+
|
| 509 |
+
# Auto-update PREVIEW HTML on any change
|
| 510 |
+
for inp in manual_inputs:
|
| 511 |
+
inp.change(subs.generate_preview_html, inputs=manual_inputs, outputs=preview_html)
|
| 512 |
+
|
| 513 |
+
# Render video button
|
| 514 |
+
preview_vid_btn.click(
|
| 515 |
+
subs.render_preview_video,
|
| 516 |
+
inputs=manual_inputs,
|
| 517 |
+
outputs=preview_vid
|
| 518 |
+
)
|
| 519 |
+
|
| 520 |
+
# Initial load
|
| 521 |
+
demo.load(subs.generate_preview_html, inputs=manual_inputs, outputs=preview_html)
|
| 522 |
+
demo.load(subs.apply_preset, inputs=[preset_input], outputs=manual_inputs) # Apply default preset on load
|
| 523 |
+
|
| 524 |
+
with gr.Row():
|
| 525 |
+
start_btn = gr.Button(i18n("Start Processing"), variant="primary")
|
| 526 |
+
stop_btn = gr.Button(i18n("Stop"), variant="stop", visible=False)
|
| 527 |
+
stop_btn.click(kill_process, outputs=[])
|
| 528 |
+
logs_output = gr.Textbox(label=i18n("Logs"), lines=10, autoscroll=True, elem_id="logs_output")
|
| 529 |
+
|
| 530 |
+
# Force scroll to bottom via JS
|
| 531 |
+
logs_output.change(fn=None, inputs=[], outputs=[], js="""
|
| 532 |
+
function() {
|
| 533 |
+
var ta = document.querySelector('#logs_output textarea');
|
| 534 |
+
if(ta) {
|
| 535 |
+
ta.scrollTop = ta.scrollHeight;
|
| 536 |
+
}
|
| 537 |
+
}
|
| 538 |
+
""")
|
| 539 |
+
results_html = gr.HTML(label=i18n("Results"))
|
| 540 |
+
|
| 541 |
+
# MUST pass all all new inputs to the run function
|
| 542 |
+
start_btn.click(run_viral_cutter, inputs=[
|
| 543 |
+
input_source, project_selector, url_input, video_upload, segments_input, viral_input, themes_input, min_dur_input, max_dur_input,
|
| 544 |
+
model_input, ai_backend_input, api_key_input, ai_model_input, chunk_size_input,
|
| 545 |
+
workflow_input, face_model_input, face_mode_input, face_detect_interval_input,
|
| 546 |
+
face_filter_thresh_input, face_two_thresh_input, face_conf_thresh_input, face_dead_zone_input, focus_active_speaker_input,
|
| 547 |
+
active_speaker_mar_input, active_speaker_score_diff_input, include_motion_input, active_speaker_motion_threshold_input, active_speaker_motion_sensitivity_input, active_speaker_decay_input,
|
| 548 |
+
use_custom_subs,
|
| 549 |
+
# Expanded Manual Inputs mapping
|
| 550 |
+
font_name_input, font_size_input, font_color_input, highlight_color_input,
|
| 551 |
+
outline_color_input, outline_thickness_input, shadow_color_input, shadow_size_input,
|
| 552 |
+
bold_input, italic_input, uppercase_input, vertical_pos_input, alignment_input,
|
| 553 |
+
# New Inputs
|
| 554 |
+
highlight_size_input, words_per_block_input, gap_limit_input, mode_input,
|
| 555 |
+
underline_input, strikeout_input, border_style_input, remove_punc_input,
|
| 556 |
+
video_quality_input, use_youtube_subs_input, translate_input
|
| 557 |
+
], outputs=[logs_output, start_btn, stop_btn, results_html])
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
with gr.Tab(i18n("Subtitle Editor")):
|
| 561 |
+
gr.Markdown(f"### {i18n('Edit Subtitles (Smart Mode)')}")
|
| 562 |
+
|
| 563 |
+
with gr.Group():
|
| 564 |
+
editor_project_dropdown = gr.Dropdown(choices=library.get_existing_projects(), label=i18n("Select Project"), value=None)
|
| 565 |
+
editor_refresh_btn = gr.Button(i18n("Refresh"), size="sm")
|
| 566 |
+
|
| 567 |
+
with gr.Group():
|
| 568 |
+
editor_file_dropdown = gr.Dropdown(choices=[], label=i18n("Select Subtitle File"), interactive=True)
|
| 569 |
+
editor_load_btn = gr.Button(i18n("Load Subtitles"), variant="secondary")
|
| 570 |
+
|
| 571 |
+
# Hidden state to store full path of currently loaded JSON
|
| 572 |
+
current_json_path = gr.State()
|
| 573 |
+
|
| 574 |
+
# The Dataframe Editor
|
| 575 |
+
# Headers: Start, End, Text
|
| 576 |
+
subtitle_dataframe = gr.Dataframe(
|
| 577 |
+
headers=["Start", "End", "Text"],
|
| 578 |
+
datatype=["str", "str", "str"],
|
| 579 |
+
col_count=(3, "fixed"),
|
| 580 |
+
interactive=True,
|
| 581 |
+
label=i18n("Subtitle Segments"),
|
| 582 |
+
wrap=True
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
with gr.Row():
|
| 586 |
+
editor_save_btn = gr.Button(i18n("💾 Save Changes"), variant="primary")
|
| 587 |
+
editor_render_single_btn = gr.Button(i18n("⚡ Render This Segment (Very-Fast)"), variant="secondary")
|
| 588 |
+
editor_render_all_btn = gr.Button(i18n("🎬 Render All (Fast)"), variant="stop")
|
| 589 |
+
|
| 590 |
+
editor_status = gr.Textbox(label=i18n("Status"), interactive=False)
|
| 591 |
+
|
| 592 |
+
# --- Callbacks for Editor ---
|
| 593 |
+
editor_refresh_btn.click(library.refresh_projects, outputs=editor_project_dropdown)
|
| 594 |
+
|
| 595 |
+
def update_file_list(proj_name):
|
| 596 |
+
if not proj_name: return gr.update(choices=[])
|
| 597 |
+
proj_path = os.path.join(VIRALS_DIR, proj_name)
|
| 598 |
+
files = editor.list_editable_files(proj_path)
|
| 599 |
+
return gr.update(choices=files, value=files[0] if files else None)
|
| 600 |
+
|
| 601 |
+
editor_project_dropdown.change(update_file_list, inputs=editor_project_dropdown, outputs=editor_file_dropdown)
|
| 602 |
+
|
| 603 |
+
def load_subs(proj_name, file_name):
|
| 604 |
+
if not proj_name or not file_name:
|
| 605 |
+
return [], None, i18n("Please select project and file.")
|
| 606 |
+
|
| 607 |
+
full_path = os.path.join(VIRALS_DIR, proj_name, 'subs', file_name)
|
| 608 |
+
data = editor.load_transcription_for_editor(full_path)
|
| 609 |
+
return data, full_path, i18n("Loaded {} segments.").format(len(data))
|
| 610 |
+
|
| 611 |
+
editor_load_btn.click(load_subs, inputs=[editor_project_dropdown, editor_file_dropdown], outputs=[subtitle_dataframe, current_json_path, editor_status])
|
| 612 |
+
|
| 613 |
+
def save_subs(json_path, df):
|
| 614 |
+
if not json_path: return i18n("No file loaded.")
|
| 615 |
+
data_list = df.values.tolist() if hasattr(df, 'values') else df
|
| 616 |
+
msg = editor.save_editor_changes(json_path, data_list)
|
| 617 |
+
return msg
|
| 618 |
+
|
| 619 |
+
editor_save_btn.click(save_subs, inputs=[current_json_path, subtitle_dataframe], outputs=editor_status)
|
| 620 |
+
|
| 621 |
+
def render_single(json_path, use_custom, font_name, font_size, font_color, highlight_color,
|
| 622 |
+
outline_color, outline_thickness, shadow_color, shadow_size,
|
| 623 |
+
is_bold, is_italic, is_uppercase,
|
| 624 |
+
h_size, w_block, gap, mode, under, strike, border_s,
|
| 625 |
+
vertical_pos, alignment, remove_punc):
|
| 626 |
+
|
| 627 |
+
if not json_path: return i18n("No file loaded.")
|
| 628 |
+
|
| 629 |
+
subtitle_config_path = os.path.join(WORKING_DIR, "temp_subtitle_config.json")
|
| 630 |
+
|
| 631 |
+
# Save config if custom subs enabled
|
| 632 |
+
if use_custom:
|
| 633 |
+
subtitle_config = {
|
| 634 |
+
"font": font_name, "base_size": int(font_size),
|
| 635 |
+
"base_color": convert_color_to_ass(font_color),
|
| 636 |
+
"highlight_color": convert_color_to_ass(highlight_color),
|
| 637 |
+
"outline_color": convert_color_to_ass(outline_color),
|
| 638 |
+
"outline_thickness": outline_thickness,
|
| 639 |
+
"shadow_color": convert_color_to_ass(shadow_color),
|
| 640 |
+
"shadow_size": shadow_size, "vertical_position": vertical_pos,
|
| 641 |
+
"alignment": alignment, "bold": 1 if is_bold else 0,
|
| 642 |
+
"italic": 1 if is_italic else 0,
|
| 643 |
+
"underline": 1 if under else 0, "strikeout": 1 if strike else 0,
|
| 644 |
+
"border_style": border_s, "words_per_block": int(w_block),
|
| 645 |
+
"gap_limit": gap, "mode": mode, "highlight_size": int(h_size),
|
| 646 |
+
"uppercase": 1 if is_uppercase else 0,
|
| 647 |
+
"remove_punctuation": remove_punc
|
| 648 |
+
}
|
| 649 |
+
try:
|
| 650 |
+
with open(subtitle_config_path, "w", encoding="utf-8") as f:
|
| 651 |
+
json.dump(subtitle_config, f, indent=4)
|
| 652 |
+
except Exception: pass
|
| 653 |
+
else:
|
| 654 |
+
# Remove temp config if it exists to ensure defaults are used
|
| 655 |
+
try:
|
| 656 |
+
if os.path.exists(subtitle_config_path):
|
| 657 |
+
os.remove(subtitle_config_path)
|
| 658 |
+
except Exception: pass
|
| 659 |
+
|
| 660 |
+
# We expect user to SAVE first, but we could auto-save.
|
| 661 |
+
# For now assume saved.
|
| 662 |
+
msg = editor.render_specific_video(json_path)
|
| 663 |
+
return msg
|
| 664 |
+
|
| 665 |
+
editor_render_single_btn.click(
|
| 666 |
+
render_single,
|
| 667 |
+
inputs=[current_json_path, use_custom_subs] + manual_inputs,
|
| 668 |
+
outputs=editor_status
|
| 669 |
+
)
|
| 670 |
+
|
| 671 |
+
def render_all(proj_name, use_custom, font_name, font_size, font_color, highlight_color,
|
| 672 |
+
outline_color, outline_thickness, shadow_color, shadow_size,
|
| 673 |
+
is_bold, is_italic, is_uppercase,
|
| 674 |
+
h_size, w_block, gap, mode, under, strike, border_s,
|
| 675 |
+
vertical_pos, alignment, remove_punc):
|
| 676 |
+
if not proj_name: return i18n("No project selected.")
|
| 677 |
+
|
| 678 |
+
# Save config
|
| 679 |
+
if use_custom:
|
| 680 |
+
subtitle_config = {
|
| 681 |
+
"font": font_name, "base_size": int(font_size),
|
| 682 |
+
"base_color": convert_color_to_ass(font_color),
|
| 683 |
+
"highlight_color": convert_color_to_ass(highlight_color),
|
| 684 |
+
"outline_color": convert_color_to_ass(outline_color),
|
| 685 |
+
"outline_thickness": outline_thickness,
|
| 686 |
+
"shadow_color": convert_color_to_ass(shadow_color),
|
| 687 |
+
"shadow_size": shadow_size, "vertical_position": vertical_pos,
|
| 688 |
+
"alignment": alignment, "bold": 1 if is_bold else 0,
|
| 689 |
+
"italic": 1 if is_italic else 0,
|
| 690 |
+
"underline": 1 if under else 0, "strikeout": 1 if strike else 0,
|
| 691 |
+
"border_style": border_s, "words_per_block": int(w_block),
|
| 692 |
+
"gap_limit": gap, "mode": mode, "highlight_size": int(h_size),
|
| 693 |
+
"uppercase": 1 if is_uppercase else 0,
|
| 694 |
+
"remove_punctuation": remove_punc
|
| 695 |
+
}
|
| 696 |
+
subtitle_config_path = os.path.join(WORKING_DIR, "temp_subtitle_config.json")
|
| 697 |
+
try:
|
| 698 |
+
with open(subtitle_config_path, "w", encoding="utf-8") as f:
|
| 699 |
+
json.dump(subtitle_config, f, indent=4)
|
| 700 |
+
except Exception: pass
|
| 701 |
+
|
| 702 |
+
proj_path = os.path.join(VIRALS_DIR, proj_name)
|
| 703 |
+
|
| 704 |
+
# IMPORTANT: Pass the config file path to the command
|
| 705 |
+
subtitle_config_path = os.path.join(WORKING_DIR, "temp_subtitle_config.json")
|
| 706 |
+
cmd = [sys.executable, MAIN_SCRIPT_PATH, "--project-path", proj_path, "--workflow", "3", "--skip-prompts"]
|
| 707 |
+
|
| 708 |
+
if use_custom and os.path.exists(subtitle_config_path):
|
| 709 |
+
cmd.extend(["--subtitle-config", subtitle_config_path])
|
| 710 |
+
|
| 711 |
+
try:
|
| 712 |
+
subprocess.Popen(cmd, cwd=WORKING_DIR)
|
| 713 |
+
return i18n("Render All started in background... Check terminal/logs.")
|
| 714 |
+
except Exception as e:
|
| 715 |
+
return i18n("Error starting render: {}").format(e)
|
| 716 |
+
|
| 717 |
+
editor_render_all_btn.click(
|
| 718 |
+
render_all,
|
| 719 |
+
inputs=[editor_project_dropdown, use_custom_subs] + manual_inputs,
|
| 720 |
+
outputs=editor_status
|
| 721 |
+
)
|
| 722 |
+
|
| 723 |
+
|
| 724 |
+
with gr.Tab(i18n("Library")):
|
| 725 |
+
gr.Markdown(f"### {i18n('Existing Projects')}")
|
| 726 |
+
with gr.Row():
|
| 727 |
+
project_dropdown = gr.Dropdown(choices=library.get_existing_projects(), label=i18n("Select Project"), value=None)
|
| 728 |
+
refresh_btn = gr.Button(i18n("Refresh List"))
|
| 729 |
+
project_gallery_html = gr.HTML()
|
| 730 |
+
refresh_btn.click(library.refresh_projects, outputs=project_dropdown)
|
| 731 |
+
def on_select_project(proj_name): return library.generate_project_gallery(proj_name)
|
| 732 |
+
project_dropdown.change(on_select_project, project_dropdown, project_gallery_html)
|
| 733 |
+
|
| 734 |
+
gr.Markdown(f"""
|
| 735 |
+
<hr>
|
| 736 |
+
<div style='text-align: center; font-size: 0.9em; color: #777;'>
|
| 737 |
+
<p>
|
| 738 |
+
<strong>{i18n('Desenvolvido por Rafael Godoy')}</strong>
|
| 739 |
+
<br>
|
| 740 |
+
{i18n('Apoie o projeto, qualquer valor é bem-vindo:')}
|
| 741 |
+
<a href='https://nubank.com.br/pagar/1ls6a4/0QpSSbWBSq' target='_blank'><strong>{i18n('Apoiar via PIX')}</strong></a>
|
| 742 |
+
<br>
|
| 743 |
+
{i18n('100% local • open source • sem assinatura')}
|
| 744 |
+
</p>
|
| 745 |
+
</div>
|
| 746 |
+
""")
|
| 747 |
+
if __name__ == "__main__":
|
| 748 |
+
import webbrowser
|
| 749 |
+
import threading
|
| 750 |
+
import time
|
| 751 |
+
import argparse
|
| 752 |
+
|
| 753 |
+
parser = argparse.ArgumentParser()
|
| 754 |
+
parser.add_argument("--colab", action="store_true", help="Run in Google Colab mode")
|
| 755 |
+
args = parser.parse_args()
|
| 756 |
+
|
| 757 |
+
if args.colab:
|
| 758 |
+
print("Running in Colab mode. Generating public link with Static Mounts...")
|
| 759 |
+
library.set_url_mode("fastapi")
|
| 760 |
+
|
| 761 |
+
# Broaden allowed paths for Colab
|
| 762 |
+
allowed_dirs = [VIRALS_DIR, WORKING_DIR, os.getcwd(), "."]
|
| 763 |
+
|
| 764 |
+
# Explicitly set static paths
|
| 765 |
+
try:
|
| 766 |
+
gr.set_static_paths(paths=allowed_dirs)
|
| 767 |
+
print(f"DEBUG: Registered static paths: {allowed_dirs}")
|
| 768 |
+
except AttributeError:
|
| 769 |
+
print("DEBUG: gr.set_static_paths not available")
|
| 770 |
+
|
| 771 |
+
print(f"DEBUG: Allowed paths for Gradio: {allowed_dirs}")
|
| 772 |
+
|
| 773 |
+
# Launch with prevent_thread_lock to allow mounting
|
| 774 |
+
app, local_url, share_url = demo.queue().launch(
|
| 775 |
+
share=True,
|
| 776 |
+
allowed_paths=allowed_dirs,
|
| 777 |
+
prevent_thread_lock=True
|
| 778 |
+
)
|
| 779 |
+
|
| 780 |
+
# Mount the VIRALS directory explicitly
|
| 781 |
+
app.mount("/virals", StaticFiles(directory=VIRALS_DIR), name="virals")
|
| 782 |
+
print(f"Mounted /virals to {VIRALS_DIR}")
|
| 783 |
+
|
| 784 |
+
demo.block_thread()
|
| 785 |
+
else:
|
| 786 |
+
# Check environment
|
| 787 |
+
is_windows = (os.name == 'nt')
|
| 788 |
+
|
| 789 |
+
library.set_url_mode("fastapi")
|
| 790 |
+
allowed_dirs = [VIRALS_DIR, WORKING_DIR, os.getcwd(), "."]
|
| 791 |
+
try:
|
| 792 |
+
gr.set_static_paths(paths=allowed_dirs)
|
| 793 |
+
except AttributeError: pass
|
| 794 |
+
|
| 795 |
+
from fastapi.responses import FileResponse
|
| 796 |
+
from fastapi import BackgroundTasks
|
| 797 |
+
|
| 798 |
+
# Helper to attach routes to any FastAPI app (whether created by Gradio or us)
|
| 799 |
+
def attach_extra_routes(fastapi_app):
|
| 800 |
+
fastapi_app.mount("/virals", StaticFiles(directory=VIRALS_DIR), name="virals")
|
| 801 |
+
|
| 802 |
+
@fastapi_app.get("/export_xml_api")
|
| 803 |
+
def export_xml_api(project: str, segment: int, background_tasks: BackgroundTasks, format: str = "premiere"):
|
| 804 |
+
try:
|
| 805 |
+
project_path = os.path.join(VIRALS_DIR, project)
|
| 806 |
+
script_path = os.path.join(WORKING_DIR, "scripts", "export_xml.py")
|
| 807 |
+
cmd = [sys.executable, script_path, "--project", project_path, "--segment", str(segment), "--format", format]
|
| 808 |
+
subprocess.run(cmd, check=True)
|
| 809 |
+
proj_name = os.path.basename(project_path)
|
| 810 |
+
zip_filename = f"export_{proj_name}_seg{segment}.zip"
|
| 811 |
+
file_path = os.path.join(project_path, zip_filename)
|
| 812 |
+
if os.path.exists(file_path):
|
| 813 |
+
return FileResponse(file_path, filename=zip_filename, media_type='application/zip')
|
| 814 |
+
else:
|
| 815 |
+
return {"error": f"File generation failed. Expected: {file_path}"}
|
| 816 |
+
except Exception as e:
|
| 817 |
+
return {"error": str(e)}
|
| 818 |
+
|
| 819 |
+
print(f"Mounted /virals to {VIRALS_DIR}")
|
| 820 |
+
|
| 821 |
+
if is_windows:
|
| 822 |
+
print("Running in Windows environment (using Gradio launch for convenience).")
|
| 823 |
+
# Windows: Use demo.launch() for convenience (auto-browser, etc)
|
| 824 |
+
app, local_url, share_url = demo.queue().launch(
|
| 825 |
+
share=False,
|
| 826 |
+
allowed_paths=allowed_dirs,
|
| 827 |
+
inbrowser=True,
|
| 828 |
+
server_name="0.0.0.0",
|
| 829 |
+
server_port=7860,
|
| 830 |
+
prevent_thread_lock=True
|
| 831 |
+
)
|
| 832 |
+
attach_extra_routes(app)
|
| 833 |
+
demo.block_thread()
|
| 834 |
+
else:
|
| 835 |
+
print("Running in Linux/Container environment (using Uvicorn for stability).")
|
| 836 |
+
# Linux/HF: Use Uvicorn for explicit loop control
|
| 837 |
+
app = FastAPI()
|
| 838 |
+
attach_extra_routes(app)
|
| 839 |
+
# Disable SSR to prevent Node proxying issues on HF Spaces
|
| 840 |
+
app = gr.mount_gradio_app(app, demo.queue(), path="/", allowed_paths=allowed_dirs, ssr_mode=False)
|
| 841 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
webui/library.py
CHANGED
|
@@ -201,15 +201,15 @@ def generate_project_gallery(project_path_name, is_full_path=False):
|
|
| 201 |
return f'<a href="{src}" target="_blank" style="color: #aaa; display: flex; align-items: center; justify-content: center; padding: 5px; border-radius: 50%; transition: color 0.2s;" title="{label}" onmouseover="this.style.color=\'{color_hover}\'" onmouseout="this.style.color=\'#aaa\'"><svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">{svg_path}</svg></a>'
|
| 202 |
|
| 203 |
# Premiere (Pr)
|
| 204 |
-
export_pr = make_export_btn("premiere", "Export Premiere XML", "#d064ff", '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><path d="M9 15h6"></path><path d="M12 12v6"></path>')
|
| 205 |
|
| 206 |
# Resolve (Dv)
|
| 207 |
-
export_dv = make_export_btn("resolve", "Export DaVinci Resolve XML", "#ff6464", '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><circle cx="12" cy="14" r="3"></circle>')
|
| 208 |
|
| 209 |
# Final Cut (Fc)
|
| 210 |
-
export_fc = make_export_btn("final-cut-pro", "Export FCP XML", "#64d0ff", '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><path d="M10 12l4 2l-4 2z"></path>')
|
| 211 |
|
| 212 |
-
export_link = f"{export_pr}{export_dv}{export_fc}"
|
| 213 |
|
| 214 |
else:
|
| 215 |
video_tag = f'<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #222; color: #666;"><span>⚠️</span><br>{i18n("External Video")}</div>'
|
|
|
|
| 201 |
return f'<a href="{src}" target="_blank" style="color: #aaa; display: flex; align-items: center; justify-content: center; padding: 5px; border-radius: 50%; transition: color 0.2s;" title="{label}" onmouseover="this.style.color=\'{color_hover}\'" onmouseout="this.style.color=\'#aaa\'"><svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">{svg_path}</svg></a>'
|
| 202 |
|
| 203 |
# Premiere (Pr)
|
| 204 |
+
export_pr = make_export_btn("premiere", "Export Premiere XML (Split Screen – known bug)", "#d064ff", '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><path d="M9 15h6"></path><path d="M12 12v6"></path>')
|
| 205 |
|
| 206 |
# Resolve (Dv)
|
| 207 |
+
# export_dv = make_export_btn("resolve", "Export DaVinci Resolve XML", "#ff6464", '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><circle cx="12" cy="14" r="3"></circle>')
|
| 208 |
|
| 209 |
# Final Cut (Fc)
|
| 210 |
+
# export_fc = make_export_btn("final-cut-pro", "Export FCP XML", "#64d0ff", '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><path d="M10 12l4 2l-4 2z"></path>')
|
| 211 |
|
| 212 |
+
export_link = f"{export_pr}" #{export_dv}{export_fc}"
|
| 213 |
|
| 214 |
else:
|
| 215 |
video_tag = f'<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #222; color: #666;"><span>⚠️</span><br>{i18n("External Video")}</div>'
|