File size: 52,961 Bytes
c3eda24 c981527 542b76c c981527 9469b3c fcd2d40 c981527 c1683bf 7d72f67 9469b3c 18a3bf2 c981527 7d72f67 18a3bf2 c981527 7d72f67 9469b3c 7d72f67 9469b3c 18a3bf2 c981527 c3eda24 c981527 c3eda24 c981527 c3eda24 c981527 b14988a c981527 b14988a c981527 b14988a c981527 c3eda24 c981527 542b76c c981527 c3eda24 c981527 fcd2d40 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 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 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 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 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 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 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
import gradio as gr
import os
import glob
import subprocess
from pathlib import Path
from datetime import datetime
import json
import sys
import time
import random
from helpers import update_model_dropdown, handle_file_upload, clear_old_output, save_uploaded_file, update_file_list, clean_model
from download import download_callback
from model import get_model_config, MODEL_CONFIGS
from processing import process_audio, auto_ensemble_process, ensemble_audio_fn, refresh_auto_output
from assets.i18n.i18n import I18nAuto
from config_manager import load_config, save_config, update_favorites, save_preset, delete_preset
import logging
from gradio_client import utils # Updated import
# Set up logging for the patch
logging.basicConfig(filename='gradio_schema.log', level=logging.DEBUG)
logger = logging.getLogger('gradio_schema')
# Patch gradio_client.utils._json_schema_to_python_type
original_json_schema_to_python_type = utils._json_schema_to_python_type
def patched_json_schema_to_python_type(schema: any, defs: dict | None = None) -> str:
logger.debug(f"Parsing schema: {schema}")
if isinstance(schema, bool):
logger.info(f"Found boolean schema: {schema}, returning 'boolean'")
return "boolean"
if not isinstance(schema, dict):
logger.warning(f"Unexpected schema type: {type(schema)}, returning 'Any'")
return "Any"
if "enum" in schema and schema.get("type") == "string":
logger.info(f"Handling enum schema: {schema['enum']}")
return f"Literal[{', '.join(repr(e) for e in schema['enum'])}]"
try:
return original_json_schema_to_python_type(schema, defs)
except utils.APIInfoParseError as e:
logger.error(f"Failed to parse schema {schema}: {e}")
return "str"
utils._json_schema_to_python_type = patched_json_schema_to_python_type
# General logging setup
logging.basicConfig(filename='sesa_gui.log', level=logging.DEBUG)
# BASE_DIR tanımı
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
CONFIG_DIR = os.path.join(BASE_DIR, "assets")
CONFIG_FILE = os.path.join(CONFIG_DIR, "config.json")
URL_FILE = os.path.join(CONFIG_DIR, "last_url.txt")
# Load user config at startup
user_config = load_config()
initial_settings = user_config["settings"]
initial_favorites = user_config["favorites"]
initial_presets = user_config["presets"]
# Ensure auto_category is valid
if "auto_category" not in initial_settings or initial_settings["auto_category"] not in MODEL_CONFIGS:
initial_settings["auto_category"] = "Vocal Models"
# Config dosyası yoksa oluştur
if not os.path.exists(CONFIG_FILE):
default_config = {
"lang": {"override": False, "selected_lang": "auto"},
"sharing": {
"method": "gradio",
"ngrok_token": "",
"port": random.randint(1000, 9000) # Random port instead of fixed
}
}
os.makedirs(CONFIG_DIR, exist_ok=True)
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
json.dump(default_config, f, indent=2)
else: # If the file exists, load and update if necessary
try:
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
config = json.load(f)
# Ensure 'lang' key exists
if "lang" not in config:
config["lang"] = {"override": False, "selected_lang": "auto"}
# Add 'sharing' key if it doesn't exist
if "sharing" not in config:
config["sharing"] = {
"method": "gradio",
"ngrok_token": "",
"port": random.randint(1000, 9000) # Random port instead of fixed
}
# Save the updated configuration
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
json.dump(config, f, indent=2)
except json.JSONDecodeError: # Handle corrupted JSON
print("Warning: config.json is corrupted. Creating a new one.")
default_config = {
"lang": {"override": False, "selected_lang": "auto"},
"sharing": {
"method": "gradio",
"ngrok_token": "",
"port": random.randint(1000, 9000) # Random port instead of fixed
}
}
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
json.dump(default_config, f, indent=2)
# I18nAuto örneği (arayüz başlamadan önce dil yüklenir)
i18n = I18nAuto()
# Çıktı formatları
OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
# Arayüz oluşturma fonksiyonu
def create_interface():
css = """
body {
background: linear-gradient(to bottom, rgba(45, 11, 11, 0.9), rgba(0, 0, 0, 0.8)), url('/content/logo.jpg') no-repeat center center fixed;
background-size: cover;
min-height: 100vh;
margin: 0;
padding: 1rem;
font-family: 'Poppins', sans-serif;
color: #C0C0C0;
overflow-x: hidden;
}
.header-text {
text-align: center;
padding: 100px 20px 20px;
color: #ff4040;
font-size: 3rem;
font-weight: 900;
text-shadow: 0 0 10px rgba(255, 64, 64, 0.5);
z-index: 1500;
animation: text-glow 2s infinite;
}
.header-subtitle {
text-align: center;
color: #C0C0C0;
font-size: 1.2rem;
font-weight: 300;
margin-top: -10px;
text-shadow: 0 0 5px rgba(255, 64, 64, 0.3);
}
.gr-tab {
background: rgba(128, 0, 0, 0.5) !important;
border-radius: 12px 12px 0 0 !important;
margin: 0 5px !important;
color: #C0C0C0 !important;
border: 1px solid #ff4040 !important;
z-index: 1500;
transition: background 0.3s ease, color 0.3s ease;
padding: 10px 20px !important;
font-size: 1.1rem !important;
}
button {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
background: #800000 !important;
border: 1px solid #ff4040 !important;
color: #C0C0C0 !important;
border-radius: 8px !important;
padding: 8px 16px !important;
box-shadow: 0 2px 10px rgba(255, 64, 64, 0.3);
}
button:hover {
transform: scale(1.05) !important;
box-shadow: 0 10px 40px rgba(255, 64, 64, 0.7) !important;
background: #ff4040 !important;
}
.compact-upload.horizontal {
display: inline-flex !important;
align-items: center !important;
gap: 8px !important;
max-width: 400px !important;
height: 40px !important;
padding: 0 12px !important;
border: 1px solid #ff4040 !important;
background: rgba(128, 0, 0, 0.5) !important;
border-radius: 8px !important;
}
.compact-dropdown {
--padding: 8px 12px !important;
--radius: 10px !important;
border: 1px solid #ff4040 !important;
background: rgba(128, 0, 0, 0.5) !important;
color: #C0C0C0 !important;
}
#custom-progress {
margin-top: 10px;
padding: 10px;
background: rgba(128, 0, 0, 0.3);
border-radius: 8px;
border: 1px solid #ff4040;
}
#progress-bar {
height: 20px;
background: linear-gradient(to right, #6e8efb, #ff4040);
border-radius: 5px;
transition: width 0.5s ease-in-out;
max-width: 100% !important;
}
.gr-accordion {
background: rgba(128, 0, 0, 0.5) !important;
border-radius: 10px !important;
border: 1px solid #ff4040 !important;
}
.footer {
text-align: center;
padding: 20px;
color: #ff4040;
font-size: 14px;
margin-top: 40px;
background: rgba(128, 0, 0, 0.3);
border-top: 1px solid #ff4040;
}
#log-accordion {
max-height: 400px;
overflow-y: auto;
background: rgba(0, 0, 0, 0.7) !important;
padding: 10px;
border-radius: 8px;
}
@keyframes text-glow {
0% { text-shadow: 0 0 5px rgba(192, 192, 192, 0); }
50% { text-shadow: 0 0 15px rgba(192, 192, 192, 1); }
100% { text-shadow: 0 0 5px rgba(192, 192, 192, 0); }
}
"""
# Load user config at startup
user_config = load_config()
initial_settings = user_config["settings"]
initial_favorites = user_config["favorites"]
initial_presets = user_config["presets"]
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
current_lang = gr.State(value=i18n.language)
favorites_state = gr.State(value=initial_favorites)
presets_state = gr.State(value=initial_presets)
header_html = gr.HTML(
value=f"""
<div class="header-text">{i18n("SESA Audio Separation")}</div>
<div class="header-subtitle">{i18n("ultimate_audio_separation")}</div>
"""
)
with gr.Tabs():
with gr.Tab(i18n("audio_separation_tab"), id="separation_tab"):
with gr.Row(equal_height=True):
with gr.Column(scale=1, min_width=380):
with gr.Accordion(i18n("input_model"), open=True) as input_model_accordion:
with gr.Tabs():
with gr.Tab(i18n("upload")) as upload_tab:
input_audio_file = gr.File(
file_types=[".wav", ".mp3", ".m4a", ".mp4", ".mkv", ".flac"],
elem_classes=["compact-upload", "horizontal", "x-narrow"],
label=""
)
with gr.Tab(i18n("path")) as path_tab:
file_path_input = gr.Textbox(placeholder=i18n("path_placeholder"))
with gr.Row():
model_category = gr.Dropdown(
label=i18n("category"),
choices=[i18n(cat) for cat in MODEL_CONFIGS.keys()],
value=i18n(initial_settings["model_category"])
)
favorite_button = gr.Button(i18n("add_favorite"), variant="secondary", scale=0)
model_dropdown = gr.Dropdown(
label=i18n("model"),
choices=update_model_dropdown(i18n(initial_settings["model_category"]), favorites=initial_favorites)["choices"],
value=initial_settings["selected_model"]
)
with gr.Accordion(i18n("settings"), open=False) as settings_accordion:
with gr.Row():
with gr.Column(scale=1):
export_format = gr.Dropdown(
label=i18n("format"),
choices=['wav FLOAT', 'flac PCM_16', 'flac PCM_24'],
value=initial_settings["export_format"]
)
with gr.Column(scale=1):
chunk_size = gr.Dropdown(
label=i18n("chunk_size"),
choices=[352800, 485100],
value=initial_settings["chunk_size"],
info=i18n("chunk_size_info")
)
with gr.Row():
with gr.Column(scale=2):
overlap = gr.Slider(
minimum=2,
maximum=50,
step=1,
label=i18n("overlap"),
value=initial_settings["overlap"],
info=i18n("overlap_info")
)
with gr.Row():
with gr.Column(scale=1):
use_tta = gr.Checkbox(
label=i18n("tta_boost"),
info=i18n("tta_info"),
value=initial_settings["use_tta"]
)
with gr.Row():
with gr.Column(scale=1):
use_demud_phaseremix_inst = gr.Checkbox(
label=i18n("phase_fix"),
info=i18n("phase_fix_info"),
value=initial_settings["use_demud_phaseremix_inst"]
)
with gr.Column(scale=1):
extract_instrumental = gr.Checkbox(
label=i18n("instrumental"),
info=i18n("instrumental_info"),
value=initial_settings["extract_instrumental"]
)
with gr.Row():
use_apollo = gr.Checkbox(
label=i18n("enhance_with_apollo"),
value=initial_settings["use_apollo"],
info=i18n("apollo_enhancement_info")
)
with gr.Group(visible=initial_settings["use_apollo"]) as apollo_settings_group:
with gr.Row():
with gr.Column(scale=1):
apollo_chunk_size = gr.Slider(
label=i18n("apollo_chunk_size"),
minimum=3,
maximum=25,
step=1,
value=initial_settings["apollo_chunk_size"],
info=i18n("apollo_chunk_size_info"),
interactive=True
)
with gr.Column(scale=1):
apollo_overlap = gr.Slider(
label=i18n("apollo_overlap"),
minimum=2,
maximum=10,
step=1,
value=initial_settings["apollo_overlap"],
info=i18n("apollo_overlap_info"),
interactive=True
)
with gr.Row():
apollo_method = gr.Dropdown(
label=i18n("apollo_processing_method"),
choices=[i18n("normal_method"), i18n("mid_side_method")],
value=i18n(initial_settings["apollo_method"]),
interactive=True
)
with gr.Row(visible=initial_settings["apollo_method"] != "mid_side_method") as apollo_normal_model_row:
apollo_normal_model = gr.Dropdown(
label=i18n("apollo_normal_model"),
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
value=initial_settings["apollo_normal_model"],
interactive=True
)
with gr.Row(visible=initial_settings["apollo_method"] == "mid_side_method") as apollo_midside_model_row:
apollo_midside_model = gr.Dropdown(
label=i18n("apollo_mid_side_model"),
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
value=initial_settings["apollo_midside_model"],
interactive=True
)
with gr.Row():
use_matchering = gr.Checkbox(
label=i18n("apply_matchering"),
value=initial_settings.get("use_matchering", False),
info=i18n("matchering_info")
)
with gr.Group(visible=initial_settings.get("use_matchering", True)) as matchering_settings_group:
matchering_passes = gr.Slider(
label=i18n("matchering_passes"),
minimum=1,
maximum=5,
step=1,
value=initial_settings.get("matchering_passes", 1),
info=i18n("matchering_passes_info"),
interactive=True
)
with gr.Row():
process_btn = gr.Button(i18n("process"), variant="primary")
clear_old_output_btn = gr.Button(i18n("reset"), variant="secondary")
clear_old_output_status = gr.Textbox(label=i18n("status"), interactive=False)
# Favorite handler
def update_favorite_button(model, favorites):
cleaned_model = clean_model(model) if model else None
is_favorited = cleaned_model in favorites if cleaned_model else False
return gr.update(value=i18n("remove_favorite") if is_favorited else i18n("add_favorite"))
def toggle_favorite(model, favorites):
if not model:
return favorites, gr.update(), gr.update()
cleaned_model = clean_model(model)
is_favorited = cleaned_model in favorites
new_favorites = update_favorites(favorites, cleaned_model, add=not is_favorited)
save_config(new_favorites, load_config()["settings"], load_config()["presets"])
category = model_category.value
return (
new_favorites,
gr.update(choices=update_model_dropdown(category, favorites=new_favorites)["choices"]),
gr.update(value=i18n("add_favorite") if is_favorited else i18n("remove_favorite"))
)
model_dropdown.change(
fn=update_favorite_button,
inputs=[model_dropdown, favorites_state],
outputs=favorite_button
)
favorite_button.click(
fn=toggle_favorite,
inputs=[model_dropdown, favorites_state],
outputs=[favorites_state, model_dropdown, favorite_button]
)
use_apollo.change(
fn=lambda x: gr.update(visible=x),
inputs=use_apollo,
outputs=apollo_settings_group
)
use_matchering.change(
fn=lambda x: gr.update(visible=x),
inputs=use_matchering,
outputs=matchering_settings_group
)
apollo_method.change(
fn=lambda x: [
gr.update(visible=x != i18n("mid_side_method")),
gr.update(visible=x == i18n("mid_side_method")),
"Apollo Universal Model" if x == i18n("mid_side_method") else None
],
inputs=apollo_method,
outputs=[apollo_normal_model_row, apollo_midside_model_row, apollo_normal_model]
)
with gr.Column(scale=2, min_width=800):
with gr.Tabs():
with gr.Tab(i18n("main_tab")) as main_tab:
with gr.Column():
original_audio = gr.Audio(label=i18n("original"), interactive=False)
with gr.Row():
vocals_audio = gr.Audio(label=i18n("vocals"), show_download_button=True, interactive=False)
instrumental_audio = gr.Audio(label=i18n("instrumental_output"), show_download_button=True, interactive=False)
other_audio = gr.Audio(label=i18n("other"), show_download_button=True, interactive=False)
with gr.Tab(i18n("details_tab")) as details_tab:
with gr.Column():
with gr.Row():
male_audio = gr.Audio(label=i18n("male"), interactive=False)
female_audio = gr.Audio(label=i18n("female"), interactive=False)
speech_audio = gr.Audio(label=i18n("speech"), interactive=False)
with gr.Row():
drum_audio = gr.Audio(label=i18n("drums"), interactive=False)
bass_audio = gr.Audio(label=i18n("bass"), interactive=False)
with gr.Row():
effects_audio = gr.Audio(label=i18n("effects"), interactive=False)
with gr.Tab(i18n("advanced_tab")) as advanced_tab:
with gr.Column():
with gr.Row():
phaseremix_audio = gr.Audio(label=i18n("phase_remix"), interactive=False)
dry_audio = gr.Audio(label=i18n("dry"), interactive=False)
with gr.Row():
music_audio = gr.Audio(label=i18n("music"), interactive=False)
karaoke_audio = gr.Audio(label=i18n("karaoke"), interactive=False)
bleed_audio = gr.Audio(label=i18n("bleed"), interactive=False)
separation_progress_html = gr.HTML(
value=f"""
<div id="custom-progress" style="margin-top: 10px;">
<div style="font-size: 1rem; color: #C0C0C0; margin-bottom: 5px;" id="progress-label">{i18n("waiting_for_processing")}</div>
<div style="width: 100%; background-color: #444; border-radius: 5px; overflow: hidden;">
<div id="progress-bar" style="width: 0%; height: 20px; background-color: #6e8efb; transition: width 0.3s;"></div>
</div>
</div>
"""
)
separation_process_status = gr.Textbox(
label=i18n("status"),
interactive=False,
placeholder=i18n("waiting_for_processing"),
visible=False
)
processing_tip = gr.Markdown(i18n("processing_tip"))
with gr.Tab(i18n("auto_ensemble_tab"), id="auto_ensemble_tab"):
with gr.Row():
with gr.Column():
with gr.Group():
auto_input_audio_file = gr.File(
file_types=[".wav", ".mp3", ".m4a", ".mp4", ".mkv", ".flac"],
label=i18n("upload_file")
)
auto_file_path_input = gr.Textbox(
label=i18n("enter_file_path"),
placeholder=i18n("file_path_placeholder"),
interactive=True
)
with gr.Accordion(i18n("advanced_settings"), open=False) as auto_settings_accordion:
with gr.Row():
auto_use_tta = gr.Checkbox(label=i18n("use_tta"), value=False)
auto_extract_instrumental = gr.Checkbox(label=i18n("instrumental_only"))
with gr.Row():
auto_overlap = gr.Slider(
label=i18n("auto_overlap"),
minimum=2,
maximum=50,
value=2,
step=1
)
auto_chunk_size = gr.Dropdown(
label=i18n("auto_chunk_size"),
choices=[352800, 485100],
value=352800
)
export_format2 = gr.Dropdown(
label=i18n("output_format"),
choices=['wav FLOAT', 'flac PCM_16', 'flac PCM_24'],
value='wav FLOAT'
)
with gr.Row():
auto_use_apollo = gr.Checkbox(
label=i18n("enhance_with_apollo"),
value=False,
info=i18n("apollo_enhancement_info")
)
with gr.Group(visible=False) as auto_apollo_settings_group:
with gr.Row():
with gr.Column(scale=1):
auto_apollo_chunk_size = gr.Slider(
label=i18n("apollo_chunk_size"),
minimum=3,
maximum=25,
step=1,
value=19,
info=i18n("apollo_chunk_size_info"),
interactive=True
)
with gr.Column(scale=1):
auto_apollo_overlap = gr.Slider(
label=i18n("apollo_overlap"),
minimum=2,
maximum=10,
step=1,
value=2,
info=i18n("apollo_overlap_info"),
interactive=True
)
with gr.Row():
auto_apollo_method = gr.Dropdown(
label=i18n("apollo_processing_method"),
choices=[i18n("normal_method"), i18n("mid_side_method")],
value=i18n("normal_method"),
interactive=True
)
with gr.Row(visible=True) as auto_apollo_normal_model_row:
auto_apollo_normal_model = gr.Dropdown(
label=i18n("apollo_normal_model"),
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
value="Apollo Universal Model",
interactive=True
)
with gr.Row(visible=False) as auto_apollo_midside_model_row:
auto_apollo_midside_model = gr.Dropdown(
label=i18n("apollo_mid_side_model"),
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
value="Apollo Universal Model",
interactive=True
)
with gr.Row():
auto_use_matchering = gr.Checkbox(
label=i18n("apply_matchering"),
value=False,
info=i18n("matchering_info")
)
with gr.Group(visible=False) as auto_matchering_settings_group:
auto_matchering_passes = gr.Slider(
label=i18n("matchering_passes"),
minimum=1,
maximum=5,
step=1,
value=1,
info=i18n("matchering_passes_info"),
interactive=True
)
with gr.Group():
model_selection_header = gr.Markdown(f"### {i18n('model_selection')}")
with gr.Row():
auto_category_dropdown = gr.Dropdown(
label=i18n("model_category"),
choices=[i18n(cat) for cat in MODEL_CONFIGS.keys()],
value=i18n("Vocal Models")
)
selected_models = gr.Dropdown(
label=i18n("selected_models"),
choices=update_model_dropdown(i18n(initial_settings["auto_category"]), favorites=initial_favorites)["choices"],
value=initial_settings["selected_models"] or [],
multiselect=True
)
with gr.Row():
preset_dropdown = gr.Dropdown(
label=i18n("select_preset"),
choices=list(initial_presets.keys()),
value=None,
allow_custom_value=False,
interactive=True
)
with gr.Row():
preset_name_input = gr.Textbox(
label=i18n("preset_name"),
placeholder=i18n("enter_preset_name"),
interactive=True
)
save_preset_btn = gr.Button(i18n("save_preset"), variant="secondary", scale=0)
delete_preset_btn = gr.Button(i18n("delete_preset"), variant="secondary", scale=0)
refresh_presets_btn = gr.Button(i18n("refresh_presets"), variant="secondary", scale=0)
with gr.Group():
ensemble_settings_header = gr.Markdown(f"### {i18n('ensemble_settings')}")
with gr.Row():
auto_ensemble_type = gr.Dropdown(
label=i18n("method"),
choices=['avg_wave', 'median_wave', 'min_wave', 'max_wave',
'avg_fft', 'median_fft', 'min_fft', 'max_fft'],
value=initial_settings["auto_ensemble_type"]
)
ensemble_recommendation = gr.Markdown(i18n("recommendation"))
auto_process_btn = gr.Button(i18n("start_processing"), variant="primary")
def load_preset(preset_name, presets, category, favorites):
if preset_name and preset_name in presets:
preset = presets[preset_name]
favorite_models = [f"{model} ⭐" if model in favorites else model for model in preset["models"]]
preset_category = preset.get("auto_category_dropdown", category)
model_choices = update_model_dropdown(preset_category, favorites=favorites)["choices"]
logger.debug(f"Preset '{preset_name}' loaded with models: {favorite_models}, category: {preset_category}")
return (
gr.update(value=preset_category),
gr.update(choices=model_choices, value=favorite_models),
gr.update(value=preset["ensemble_method"])
)
logger.debug(f"Preset '{preset_name}' not found.")
return gr.update(), gr.update(), gr.update()
def sync_presets():
config = load_config()
return config["presets"], gr.update(choices=list(config["presets"].keys()), value=None)
preset_dropdown.change(
fn=load_preset,
inputs=[preset_dropdown, presets_state, auto_category_dropdown, favorites_state],
outputs=[auto_category_dropdown, selected_models, auto_ensemble_type]
)
def handle_save_preset(preset_name, models, ensemble_method, presets, favorites, auto_category_dropdown):
if not preset_name:
return gr.update(), presets, i18n("no_preset_name_provided")
if not models and not favorites:
return gr.update(), presets, i18n("no_models_selected_for_preset")
new_presets = save_preset(
presets,
preset_name,
models,
ensemble_method,
auto_category_dropdown=auto_category_dropdown
)
save_config(favorites, load_config()["settings"], new_presets)
logger.debug(f"Preset dropdown updated with choices: {list(new_presets.keys())}")
return gr.update(choices=list(new_presets.keys()), value=None), new_presets, i18n("preset_saved").format(preset_name)
save_preset_btn.click(
fn=handle_save_preset,
inputs=[preset_name_input, selected_models, auto_ensemble_type, presets_state, favorites_state, auto_category_dropdown],
outputs=[preset_dropdown, presets_state]
)
def handle_delete_preset(preset_name, presets):
if not preset_name or preset_name not in presets:
return gr.update(), presets
new_presets = delete_preset(presets, preset_name)
save_config(load_config()["favorites"], load_config()["settings"], new_presets)
return gr.update(choices=list(new_presets.keys()), value=None), new_presets
delete_preset_btn.click(
fn=handle_delete_preset,
inputs=[preset_dropdown, presets_state],
outputs=[preset_dropdown, presets_state]
)
refresh_presets_btn.click(
fn=sync_presets,
inputs=[],
outputs=[presets_state, preset_dropdown]
)
auto_use_apollo.change(
fn=lambda x: gr.update(visible=x),
inputs=auto_use_apollo,
outputs=auto_apollo_settings_group
)
auto_use_matchering.change(
fn=lambda x: gr.update(visible=x),
inputs=auto_use_matchering,
outputs=auto_matchering_settings_group
)
auto_apollo_method.change(
fn=lambda x: [
gr.update(visible=x != i18n("mid_side_method")),
gr.update(visible=x == i18n("mid_side_method")),
"Apollo Universal Model" if x == i18n("mid_side_method") else None
],
inputs=auto_apollo_method,
outputs=[auto_apollo_normal_model_row, auto_apollo_midside_model_row, auto_apollo_normal_model]
)
with gr.Column():
with gr.Tabs():
with gr.Tab(i18n("original_audio_tab")) as original_audio_tab:
original_audio2 = gr.Audio(
label=i18n("original_audio"),
interactive=False,
every=1,
elem_id="original_audio_player"
)
with gr.Tab(i18n("ensemble_result_tab")) as ensemble_result_tab:
auto_output_audio = gr.Audio(
label=i18n("output_preview"),
show_download_button=True,
interactive=False
)
refresh_output_btn = gr.Button(i18n("refresh_output"), variant="secondary")
ensemble_progress_html = gr.HTML(
value=f"""
<div id="custom-progress" style="margin-top: 10px;">
<div style="font-size: 1rem; color: #C0C0C0; margin-bottom: 5px;" id="progress-label">{i18n("waiting_for_processing")}</div>
<div style="width: 100%; background-color: #444; border-radius: 5px; overflow: hidden;">
<div id="progress-bar" style="width: 0%; height: 20px; background-color: #6e8efb; transition: width 0.3s;"></div>
</div>
</div>
"""
)
ensemble_process_status = gr.Textbox(
label=i18n("status"),
interactive=False,
placeholder=i18n("waiting_for_processing"),
visible=False
)
with gr.Tab(i18n("download_sources_tab"), id="download_tab"):
with gr.Row():
with gr.Column():
gr.Markdown(f"### {i18n('direct_links')}")
direct_url_input = gr.Textbox(label=i18n("audio_file_url"))
direct_download_btn = gr.Button(i18n("download_from_url"), variant="secondary")
direct_download_status = gr.Textbox(label=i18n("download_status"))
direct_download_output = gr.File(label=i18n("downloaded_file"), interactive=False)
with gr.Column():
gr.Markdown(f"### {i18n('cookie_management')}")
cookie_file = gr.File(
label=i18n("upload_cookies_txt"),
file_types=[".txt"],
interactive=True,
elem_id="cookie_upload"
)
cookie_info = gr.Markdown(i18n("cookie_info"))
with gr.Tab(i18n("manual_ensemble_tab"), id="manual_ensemble_tab"):
with gr.Row(equal_height=True):
with gr.Column(scale=1, min_width=400):
with gr.Accordion(i18n("input_sources"), open=True) as input_sources_accordion:
with gr.Row():
refresh_btn = gr.Button(i18n("refresh"), variant="secondary", size="sm")
ensemble_type = gr.Dropdown(
label=i18n("ensemble_algorithm"),
choices=['avg_wave', 'median_wave', 'min_wave', 'max_wave',
'avg_fft', 'median_fft', 'min_fft', 'max_fft'],
value='avg_wave'
)
file_dropdown_header = gr.Markdown(f"### {i18n('select_audio_files')}")
file_path = os.path.join(Path.home(), 'Music-Source-Separation', 'output')
initial_files = glob.glob(f"{file_path}/*.wav") + glob.glob(os.path.join(BASE_DIR, 'Music-Source-Separation-Training', 'old_output', '*.wav'))
file_dropdown = gr.Dropdown(
choices=initial_files,
label=i18n("available_files"),
multiselect=True,
interactive=True,
elem_id="file-dropdown"
)
weights_input = gr.Textbox(
label=i18n("custom_weights"),
placeholder=i18n("custom_weights_placeholder"),
info=i18n("custom_weights_info")
)
with gr.Column(scale=2, min_width=800):
with gr.Tabs():
with gr.Tab(i18n("result_preview_tab")) as result_preview_tab:
ensemble_output_audio = gr.Audio(
label=i18n("ensembled_output"),
interactive=False,
show_download_button=True,
elem_id="output-audio"
)
with gr.Tab(i18n("processing_log_tab")) as processing_log_tab:
with gr.Accordion(i18n("processing_details"), open=True, elem_id="log-accordion"):
ensemble_status = gr.Textbox(
label="",
interactive=False,
placeholder=i18n("processing_log_placeholder"),
lines=10,
max_lines=20,
elem_id="log-box"
)
with gr.Row():
ensemble_process_btn = gr.Button(
i18n("process_ensemble"),
variant="primary",
size="sm",
elem_id="process-btn"
)
def save_settings_on_process(*args):
apollo_method_value = args[11]
backend_apollo_method = "mid_side_method" if apollo_method_value == i18n("mid_side_method") else "normal_method"
cleaned_model = clean_model(args[1]) if args[1] else None
settings = {
"chunk_size": args[2],
"overlap": args[3],
"export_format": args[4],
"use_tta": args[5],
"use_demud_phaseremix_inst": args[6],
"extract_instrumental": args[7],
"use_apollo": args[8],
"apollo_chunk_size": args[9],
"apollo_overlap": args[10],
"apollo_method": backend_apollo_method,
"apollo_normal_model": args[12],
"apollo_midside_model": args[13],
"use_matchering": args[14],
"matchering_passes": args[15],
"model_category": args[16],
"selected_model": cleaned_model,
"auto_ensemble_type": args[17]
}
save_config(load_config()["favorites"], settings, load_config()["presets"])
modified_args = list(args)
modified_args[1] = cleaned_model
modified_args[17] = cleaned_model
return process_audio(*modified_args)
def save_auto_ensemble_settings(*args):
settings = load_config()["settings"]
settings["auto_ensemble_type"] = args[7]
settings["use_matchering"] = args[14]
settings["matchering_passes"] = args[15]
save_config(load_config()["favorites"], settings, load_config()["presets"])
output_audio, status, progress_html = None, i18n("waiting_for_processing"), ensemble_progress_html.value
for update in auto_ensemble_process(*args):
if isinstance(update, tuple) and len(update) == 3:
output_audio, status, progress_html = update
return output_audio, status, progress_html
def update_category_dropdowns(cat):
logging.debug(f"Input category: {cat}")
eng_cat = next((k for k in MODEL_CONFIGS.keys() if i18n(k) == cat), list(MODEL_CONFIGS.keys())[0])
logging.debug(f"Using English category: {eng_cat}")
choices = update_model_dropdown(eng_cat, favorites=load_config()["favorites"])["choices"]
logging.debug(f"Model choices: {choices}")
return gr.update(choices=choices), gr.update(choices=choices)
model_category.change(
fn=update_category_dropdowns,
inputs=model_category,
outputs=[model_dropdown, selected_models]
)
clear_old_output_btn.click(fn=clear_old_output, outputs=clear_old_output_status)
input_audio_file.upload(
fn=lambda x, y: handle_file_upload(x, y, is_auto_ensemble=False),
inputs=[input_audio_file, file_path_input],
outputs=[input_audio_file, original_audio]
)
file_path_input.change(
fn=lambda x, y: handle_file_upload(x, y, is_auto_ensemble=False),
inputs=[input_audio_file, file_path_input],
outputs=[input_audio_file, original_audio]
)
auto_input_audio_file.upload(
fn=lambda x, y: handle_file_upload(x, y, is_auto_ensemble=True),
inputs=[auto_input_audio_file, auto_file_path_input],
outputs=[auto_input_audio_file, original_audio2]
)
auto_file_path_input.change(
fn=lambda x, y: handle_file_upload(x, y, is_auto_ensemble=True),
inputs=[auto_input_audio_file, auto_file_path_input],
outputs=[auto_input_audio_file, original_audio2]
)
auto_category_dropdown.change(
fn=lambda cat: gr.update(choices=update_model_dropdown(next((k for k in MODEL_CONFIGS.keys() if i18n(k) == cat), list(MODEL_CONFIGS.keys())[0]), favorites=load_config()["favorites"])["choices"]),
inputs=auto_category_dropdown,
outputs=selected_models
)
def debug_inputs(*args):
input_names = [
"input_audio_file", "model_dropdown", "chunk_size", "overlap", "export_format",
"use_tta", "use_demud_phaseremix_inst", "extract_instrumental",
"use_apollo", "apollo_chunk_size", "apollo_overlap",
"apollo_method", "apollo_normal_model", "apollo_midside_model",
"use_matchering", "matchering_passes", "model_category", "selected_model"
]
cleaned_args = list(args)
cleaned_args[1] = clean_model(cleaned_args[1]) if cleaned_args[1] else None
cleaned_args[17] = clean_model(cleaned_args[17]) if cleaned_args[17] else None
for name, value in zip(input_names, cleaned_args):
logger.debug(f"UI Input - {name}: {value}")
return args
process_btn.click(
fn=lambda *args: save_settings_on_process(*debug_inputs(*args)),
inputs=[
input_audio_file, model_dropdown, chunk_size, overlap, export_format,
use_tta, use_demud_phaseremix_inst, extract_instrumental,
use_apollo, apollo_chunk_size, apollo_overlap,
apollo_method, apollo_normal_model, apollo_midside_model,
use_matchering, matchering_passes, model_category, model_dropdown
],
outputs=[
vocals_audio, instrumental_audio, phaseremix_audio, drum_audio, karaoke_audio,
other_audio, bass_audio, effects_audio, speech_audio, bleed_audio, music_audio,
dry_audio, male_audio, female_audio,
separation_process_status, separation_progress_html
]
)
auto_process_btn.click(
fn=save_auto_ensemble_settings,
inputs=[
auto_input_audio_file,
selected_models,
auto_chunk_size,
auto_overlap,
export_format2,
auto_use_tta,
auto_extract_instrumental,
auto_ensemble_type,
gr.State(None),
auto_use_apollo,
auto_apollo_normal_model,
auto_apollo_chunk_size,
auto_apollo_overlap,
auto_apollo_method,
auto_use_matchering,
auto_matchering_passes,
auto_apollo_midside_model
],
outputs=[auto_output_audio, ensemble_process_status, ensemble_progress_html]
)
direct_download_btn.click(
fn=download_callback,
inputs=[direct_url_input, gr.State('direct'), cookie_file],
outputs=[direct_download_output, direct_download_status, input_audio_file, auto_input_audio_file, original_audio, original_audio2]
)
refresh_output_btn.click(
fn=refresh_auto_output,
inputs=[],
outputs=[auto_output_audio, ensemble_process_status]
)
refresh_btn.click(fn=update_file_list, outputs=file_dropdown)
ensemble_process_btn.click(fn=ensemble_audio_fn, inputs=[file_dropdown, ensemble_type, weights_input], outputs=[ensemble_output_audio, ensemble_status])
return demo |