CoolFace
Apppublic

ASesYusuf1/SESA_Audio_Separation

sourceHugging Facemitupdated 6mo agoView on Hugging Face
14likes
gui.py1552 linesDownload Raw Back to root
1import gradio as gr2import os3import glob4import subprocess5from pathlib import Path6from datetime import datetime7import json8import sys9import time10import random11from helpers import update_model_dropdown, handle_file_upload, clear_old_output, save_uploaded_file, update_file_list, clean_model, get_model_categories12from download import download_callback13from model import get_model_config, MODEL_CONFIGS, get_all_model_configs_with_custom, add_custom_model, delete_custom_model, get_custom_models_list, SUPPORTED_MODEL_TYPES, load_custom_models, get_model_chunk_size14from processing import process_audio, auto_ensemble_process, ensemble_audio_fn, refresh_auto_output15from assets.i18n.i18n import I18nAuto16from config_manager import load_config, save_config, update_favorites, save_preset, delete_preset17from phase_fixer import SOURCE_MODELS, TARGET_MODELS18import logging19logging.basicConfig(filename='sesa_gui.log', level=logging.WARNING)20 21# BASE_DIR tanımı22BASE_DIR = os.path.dirname(os.path.abspath(__file__))23CONFIG_DIR = os.path.join(BASE_DIR, "assets")24CONFIG_FILE = os.path.join(CONFIG_DIR, "config.json")25URL_FILE = os.path.join(CONFIG_DIR, "last_url.txt")26 27# Load user config at startup28user_config = load_config()29initial_settings = user_config["settings"]30initial_favorites = user_config["favorites"]31initial_presets = user_config["presets"]32 33# Ensure auto_category is valid34if "auto_category" not in initial_settings or initial_settings["auto_category"] not in MODEL_CONFIGS:35    initial_settings["auto_category"] = "Vocal Models"36 37# Config dosyası yoksa oluştur38if not os.path.exists(CONFIG_FILE):39    default_config = {40        "lang": {"override": False, "selected_lang": "auto"},41        "sharing": {42            "method": "gradio",43            "ngrok_token": "",44            "port": random.randint(1000, 9000)  # Random port instead of fixed45        }46    }47    os.makedirs(CONFIG_DIR, exist_ok=True)48    with open(CONFIG_FILE, "w", encoding="utf-8") as f:49        json.dump(default_config, f, indent=2)50else:  # If the file exists, load and update if necessary51    try:52        with open(CONFIG_FILE, "r", encoding="utf-8") as f:53            config = json.load(f)54        # Ensure 'lang' key exists55        if "lang" not in config:56            config["lang"] = {"override": False, "selected_lang": "auto"}57        # Add 'sharing' key if it doesn't exist58        if "sharing" not in config:59            config["sharing"] = {60                "method": "gradio",61                "ngrok_token": "",62                "port": random.randint(1000, 9000)  # Random port instead of fixed63            }64        # Save the updated configuration65        with open(CONFIG_FILE, "w", encoding="utf-8") as f:66            json.dump(config, f, indent=2)67    except json.JSONDecodeError:  # Handle corrupted JSON68        print("Warning: config.json is corrupted. Creating a new one.")69        default_config = {70            "lang": {"override": False, "selected_lang": "auto"},71            "sharing": {72                "method": "gradio",73                "ngrok_token": "",74                "port": random.randint(1000, 9000)  # Random port instead of fixed75            }76        }77        with open(CONFIG_FILE, "w", encoding="utf-8") as f:78            json.dump(default_config, f, indent=2)79 80# I18nAuto örneği (arayüz başlamadan önce dil yüklenir)81i18n = I18nAuto()82 83# Çıktı formatları84OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']85 86# Arayüz oluşturma fonksiyonu87def create_interface():88    css = """89    body {90        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;91        background-size: cover;92        min-height: 100vh;93        margin: 0;94        padding: 1rem;95        font-family: 'Poppins', sans-serif;96        color: #C0C0C0;97        overflow-x: hidden;98    }99    .header-text {100        text-align: center;101        padding: 100px 20px 20px;102        color: #ff4040;103        font-size: 3rem;104        font-weight: 900;105        text-shadow: 0 0 10px rgba(255, 64, 64, 0.5);106        z-index: 1500;107        animation: text-glow 2s infinite;108    }109    .header-subtitle {110        text-align: center;111        color: #C0C0C0;112        font-size: 1.2rem;113        font-weight: 300;114        margin-top: -10px;115        text-shadow: 0 0 5px rgba(255, 64, 64, 0.3);116    }117    .gr-tab {118        background: rgba(128, 0, 0, 0.5) !important;119        border-radius: 12px 12px 0 0 !important;120        margin: 0 5px !important;121        color: #C0C0C0 !important;122        border: 1px solid #ff4040 !important;123        z-index: 1500;124        transition: background 0.3s ease, color 0.3s ease;125        padding: 10px 20px !important;126        font-size: 1.1rem !important;127    }128    button {129        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;130        background: #800000 !important;131        border: 1px solid #ff4040 !important;132        color: #C0C0C0 !important;133        border-radius: 8px !important;134        padding: 8px 16px !important;135        box-shadow: 0 2px 10px rgba(255, 64, 64, 0.3);136    }137    button:hover {138        transform: scale(1.05) !important;139        box-shadow: 0 10px 40px rgba(255, 64, 64, 0.7) !important;140        background: #ff4040 !important;141    }142    .compact-upload.horizontal {143        display: inline-flex !important;144        align-items: center !important;145        gap: 8px !important;146        max-width: 400px !important;147        height: 40px !important;148        padding: 0 12px !important;149        border: 1px solid #ff4040 !important;150        background: rgba(128, 0, 0, 0.5) !important;151        border-radius: 8px !important;152    }153    .compact-dropdown {154        --padding: 8px 12px !important;155        --radius: 10px !important;156        border: 1px solid #ff4040 !important;157        background: rgba(128, 0, 0, 0.5) !important;158        color: #C0C0C0 !important;159    }160    #custom-progress {161        margin-top: 10px;162        padding: 10px;163        background: rgba(128, 0, 0, 0.3);164        border-radius: 8px;165        border: 1px solid #ff4040;166    }167    #progress-bar {168        height: 20px;169        background: linear-gradient(90deg, #6e8efb, #a855f7, #ff4040);170        background-size: 200% 100%;171        border-radius: 5px;172        transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);173        max-width: 100% !important;174    }175    @keyframes progress-shimmer {176        0% { background-position: 200% 0; }177        100% { background-position: -200% 0; }178    }179    #progress-bar[data-active="true"] {180        animation: progress-shimmer 2s linear infinite;181    }182    .gr-accordion {183        background: rgba(128, 0, 0, 0.5) !important;184        border-radius: 10px !important;185        border: 1px solid #ff4040 !important;186    }187    .footer {188        text-align: center;189        padding: 20px;190        color: #ff4040;191        font-size: 14px;192        margin-top: 40px;193        background: rgba(128, 0, 0, 0.3);194        border-top: 1px solid #ff4040;195    }196    #log-accordion {197        max-height: 400px;198        overflow-y: auto;199        background: rgba(0, 0, 0, 0.7) !important;200        padding: 10px;201        border-radius: 8px;202    }203    @keyframes text-glow {204        0% { text-shadow: 0 0 5px rgba(192, 192, 192, 0); }205        50% { text-shadow: 0 0 15px rgba(192, 192, 192, 1); }206        100% { text-shadow: 0 0 5px rgba(192, 192, 192, 0); }207    }208    """209 210    # Load user config at startup211    user_config = load_config()212    initial_settings = user_config["settings"]213    initial_favorites = user_config["favorites"]214    initial_presets = user_config["presets"]215 216    with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:217        current_lang = gr.State(value=i18n.language)218        favorites_state = gr.State(value=initial_favorites)219        presets_state = gr.State(value=initial_presets)220 221        header_html = gr.HTML(222            value=f"""223            <div class="header-text">{i18n("SESA Audio Separation")}</div>224            <div class="header-subtitle">{i18n("ultimate_audio_separation")}</div>225            """226        )227 228        with gr.Tabs():229            with gr.Tab(i18n("audio_separation_tab"), id="separation_tab"):230                with gr.Row(equal_height=True):231                    with gr.Column(scale=1, min_width=380):232                        with gr.Accordion(i18n("input_model"), open=True) as input_model_accordion:233                            with gr.Tabs():234                                with gr.Tab(i18n("upload")) as upload_tab:235                                    input_audio_file = gr.File(236                                        file_types=[".wav", ".mp3", ".m4a", ".mp4", ".mkv", ".flac"],237                                        elem_classes=["compact-upload", "horizontal", "x-narrow"],238                                        label=""239                                    )240                                with gr.Tab(i18n("path")) as path_tab:241                                    file_path_input = gr.Textbox(placeholder=i18n("path_placeholder"))242 243                            with gr.Row():244                                model_category = gr.Dropdown(245                                    label=i18n("category"),246                                    choices=[i18n(cat) for cat in get_all_model_configs_with_custom().keys()],247                                    value=i18n(initial_settings["model_category"])248                                )249                                favorite_button = gr.Button(i18n("add_favorite"), variant="secondary", scale=0)250 251                            model_dropdown = gr.Dropdown(252                                label=i18n("model"),253                                choices=update_model_dropdown(i18n(initial_settings["model_category"]), favorites=initial_favorites)["choices"],254                                value=initial_settings["selected_model"]255                            )256 257                        with gr.Accordion(i18n("settings"), open=False) as settings_accordion:258                            with gr.Row():259                                with gr.Column(scale=1):260                                    export_format = gr.Dropdown(261                                        label=i18n("format"),262                                        choices=['wav FLOAT', 'flac PCM_16', 'flac PCM_24'],263                                        value=initial_settings["export_format"]264                                    )265                                with gr.Column(scale=1):266                                    _init_cs_mode = initial_settings.get("chunk_size_mode", "base")267                                    chunk_size_mode = gr.Radio(268                                        label=i18n("chunk_size_mode"),269                                        choices=["base", "custom", "yaml"],270                                        value=_init_cs_mode,271                                        info=i18n("chunk_size_mode_info")272                                    )273                                    chunk_size = gr.Dropdown(274                                        label=i18n("chunk_size"),275                                        choices=[352800, 485100],276                                        value=initial_settings["chunk_size"],277                                        info=i18n("chunk_size_info"),278                                        visible=(_init_cs_mode == "base")279                                    )280                                    chunk_size_custom = gr.Number(281                                        label=i18n("chunk_size_custom_label"),282                                        value=initial_settings.get("chunk_size_custom", 352800),283                                        precision=0,284                                        info=i18n("chunk_size_custom_info"),285                                        visible=(_init_cs_mode == "custom")286                                    )287                                    chunk_size_yaml_display = gr.Textbox(288                                        label=i18n("chunk_size_yaml_label"),289                                        value=i18n("chunk_size_yaml_not_downloaded"),290                                        interactive=False,291                                        info=i18n("chunk_size_yaml_display_info"),292                                        visible=(_init_cs_mode == "yaml")293                                    )294 295                            with gr.Row():296                                with gr.Column(scale=2):297                                    overlap = gr.Slider(298                                        minimum=2,299                                        maximum=50,300                                        step=1,301                                        label=i18n("overlap"),302                                        value=initial_settings["overlap"],303                                        info=i18n("overlap_info")304                                    )305 306                            with gr.Accordion(i18n("backend_settings"), open=True) as backend_settings_accordion:307                                gr.Markdown(f"### {i18n('inference_backend')} - {i18n('ultra_optimized_pytorch')}")308                                gr.Markdown(f"**{i18n('default_active_max_speed')}**")309                                310                                with gr.Row():311                                    optimize_mode = gr.Dropdown(312                                        label=i18n("optimization_mode"),313                                        choices=['channels_last', 'compile', 'default'],314                                        value=initial_settings.get("optimize_mode", "channels_last"),315                                        info=f"channels_last: {i18n('channels_last_mode')} | compile: {i18n('compile_mode')} | default: {i18n('default_mode')}"316                                    )317                                318                                with gr.Row():319                                    enable_amp = gr.Checkbox(320                                        label=i18n("mixed_precision_amp"),321                                        value=initial_settings.get("enable_amp", True),322                                        info=i18n("mixed_precision_info")323                                    )324                                    enable_tf32 = gr.Checkbox(325                                        label=i18n("tf32_acceleration"),326                                        value=initial_settings.get("enable_tf32", True),327                                        info=i18n("tf32_acceleration_info")328                                    )329                                    enable_cudnn_benchmark = gr.Checkbox(330                                        label=i18n("cudnn_benchmark"),331                                        value=initial_settings.get("enable_cudnn_benchmark", True),332                                        info=i18n("cudnn_benchmark_info")333                                    )334 335                            with gr.Row():336                                with gr.Column(scale=1):337                                    use_tta = gr.Checkbox(338                                        label=i18n("tta_boost"),339                                        info=i18n("tta_info"),340                                        value=initial_settings["use_tta"]341                                    )342 343                            with gr.Row():344                                with gr.Column(scale=1):345                                    use_demud_phaseremix_inst = gr.Checkbox(346                                        label=i18n("phase_fix"),347                                        info=i18n("phase_fix_info"),348                                        value=initial_settings["use_demud_phaseremix_inst"]349                                    )350 351                                with gr.Column(scale=1):352                                    extract_instrumental = gr.Checkbox(353                                        label=i18n("instrumental"),354                                        info=i18n("instrumental_info"),355                                        value=initial_settings["extract_instrumental"]356                                    )357 358                            with gr.Row():359                                use_apollo = gr.Checkbox(360                                    label=i18n("enhance_with_apollo"),361                                    value=initial_settings["use_apollo"],362                                    info=i18n("apollo_enhancement_info")363                                )364 365                            with gr.Group(visible=initial_settings["use_apollo"]) as apollo_settings_group:366                                with gr.Row():367                                    with gr.Column(scale=1):368                                        apollo_chunk_size = gr.Slider(369                                            label=i18n("apollo_chunk_size"),370                                            minimum=3,371                                            maximum=25,372                                            step=1,373                                            value=initial_settings["apollo_chunk_size"],374                                            info=i18n("apollo_chunk_size_info"),375                                            interactive=True376                                        )377                                    with gr.Column(scale=1):378                                        apollo_overlap = gr.Slider(379                                            label=i18n("apollo_overlap"),380                                            minimum=2,381                                            maximum=10,382                                            step=1,383                                            value=initial_settings["apollo_overlap"],384                                            info=i18n("apollo_overlap_info"),385                                            interactive=True386                                        )387 388                                with gr.Row():389                                    apollo_method = gr.Dropdown(390                                        label=i18n("apollo_processing_method"),391                                        choices=[i18n("normal_method"), i18n("mid_side_method")],392                                        value=i18n(initial_settings["apollo_method"]),393                                        interactive=True394                                    )395 396                                with gr.Row(visible=initial_settings["apollo_method"] != "mid_side_method") as apollo_normal_model_row:397                                    apollo_normal_model = gr.Dropdown(398                                        label=i18n("apollo_normal_model"),399                                        choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],400                                        value=initial_settings["apollo_normal_model"],401                                        interactive=True402                                    )403 404                                with gr.Row(visible=initial_settings["apollo_method"] == "mid_side_method") as apollo_midside_model_row:405                                    apollo_midside_model = gr.Dropdown(406                                        label=i18n("apollo_mid_side_model"),407                                        choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],408                                        value=initial_settings["apollo_midside_model"],409                                        interactive=True410                                    )411 412                            with gr.Row():413                                use_matchering = gr.Checkbox(414                                    label=i18n("apply_matchering"),415                                    value=initial_settings.get("use_matchering", False),416                                    info=i18n("matchering_info")417                                )418 419                            with gr.Group(visible=initial_settings.get("use_matchering", True)) as matchering_settings_group:420                                matchering_passes = gr.Slider(421                                    label=i18n("matchering_passes"),422                                    minimum=1,423                                    maximum=5,424                                    step=1,425                                    value=initial_settings.get("matchering_passes", 1),426                                                                        info=i18n("matchering_passes_info"),427                                    interactive=True428                                )429 430                        with gr.Row():431                            process_btn = gr.Button(i18n("process"), variant="primary")432                            clear_old_output_btn = gr.Button(i18n("reset"), variant="secondary")433                        clear_old_output_status = gr.Textbox(label=i18n("status"), interactive=False)434 435                        # Favorite handler + chunk size auto-update436                        def update_favorite_button(model, favorites, cs_mode):437                            cleaned_model = clean_model(model) if model else None438                            is_favorited = cleaned_model in favorites if cleaned_model else False439                            fav_btn = gr.update(value=i18n("remove_favorite") if is_favorited else i18n("add_favorite"))440                            chunk_update = gr.update()441                            yaml_update = gr.update()442                            if cleaned_model:443                                native_chunk = get_model_chunk_size(cleaned_model)444                                if cs_mode == "base" and native_chunk and native_chunk in [352800, 485100]:445                                    chunk_update = gr.update(value=native_chunk)446                                if cs_mode == "yaml":447                                    if native_chunk:448                                        yaml_update = gr.update(value=i18n("chunk_size_yaml_detected").format(native_chunk))449                                    else:450                                        yaml_update = gr.update(value=i18n("chunk_size_yaml_not_downloaded"))451                            return fav_btn, chunk_update, yaml_update452 453                        def toggle_favorite(model, favorites):454                            if not model:455                                return favorites, gr.update(), gr.update()456                            cleaned_model = clean_model(model)457                            is_favorited = cleaned_model in favorites458                            new_favorites = update_favorites(favorites, cleaned_model, add=not is_favorited)459                            save_config(new_favorites, load_config()["settings"], load_config()["presets"])460                            category = model_category.value461                            return (462                                new_favorites,463                                gr.update(choices=update_model_dropdown(category, favorites=new_favorites)["choices"]),464                                gr.update(value=i18n("add_favorite") if is_favorited else i18n("remove_favorite"))465                            )466 467                        def on_chunk_size_mode_change(mode, model):468                            cleaned = clean_model(model) if model else None469                            native_chunk = get_model_chunk_size(cleaned) if cleaned else None470                            yaml_text = (471                                i18n("chunk_size_yaml_detected").format(native_chunk)472                                if native_chunk else i18n("chunk_size_yaml_not_downloaded")473                            )474                            return (475                                gr.update(visible=(mode == "base")),476                                gr.update(visible=(mode == "custom")),477                                gr.update(visible=(mode == "yaml"), value=yaml_text),478                            )479 480                        chunk_size_mode.change(481                            fn=on_chunk_size_mode_change,482                            inputs=[chunk_size_mode, model_dropdown],483                            outputs=[chunk_size, chunk_size_custom, chunk_size_yaml_display]484                        )485 486                        model_dropdown.change(487                            fn=update_favorite_button,488                            inputs=[model_dropdown, favorites_state, chunk_size_mode],489                            outputs=[favorite_button, chunk_size, chunk_size_yaml_display]490                        )491 492                        favorite_button.click(493                            fn=toggle_favorite,494                            inputs=[model_dropdown, favorites_state],495                            outputs=[favorites_state, model_dropdown, favorite_button]496                        )497 498                        use_apollo.change(499                            fn=lambda x: gr.update(visible=x),500                            inputs=use_apollo,501                            outputs=apollo_settings_group502                        )503 504                        use_matchering.change(505                            fn=lambda x: gr.update(visible=x),506                            inputs=use_matchering,507                            outputs=matchering_settings_group508                        )509 510                        apollo_method.change(511                            fn=lambda x: [512                                gr.update(visible=x != i18n("mid_side_method")),513                                gr.update(visible=x == i18n("mid_side_method")),514                                "Apollo Universal Model" if x == i18n("mid_side_method") else None515                            ],516                            inputs=apollo_method,517                            outputs=[apollo_normal_model_row, apollo_midside_model_row, apollo_normal_model]518                        )519 520                    with gr.Column(scale=2, min_width=800):521                        with gr.Tabs():522                            with gr.Tab(i18n("main_tab")) as main_tab:523                                with gr.Column():524                                    original_audio = gr.Audio(label=i18n("original"), interactive=False)525                                    with gr.Row():526                                        vocals_audio = gr.Audio(label=i18n("vocals"))527                                        instrumental_audio = gr.Audio(label=i18n("instrumental_output"))528                                        other_audio = gr.Audio(label=i18n("other"))529 530                            with gr.Tab(i18n("details_tab")) as details_tab:531                                with gr.Column():532                                    with gr.Row():533                                        male_audio = gr.Audio(label=i18n("male"))534                                        female_audio = gr.Audio(label=i18n("female"))535                                        speech_audio = gr.Audio(label=i18n("speech"))536                                    with gr.Row():537                                        drum_audio = gr.Audio(label=i18n("drums"))538                                        bass_audio = gr.Audio(label=i18n("bass"))539                                    with gr.Row():540                                        effects_audio = gr.Audio(label=i18n("effects"))541 542                            with gr.Tab(i18n("advanced_tab")) as advanced_tab:543                                with gr.Column():544                                    with gr.Row():545                                        phaseremix_audio = gr.Audio(label=i18n("phase_remix"))546                                        dry_audio = gr.Audio(label=i18n("dry"))547                                    with gr.Row():548                                        music_audio = gr.Audio(label=i18n("music"))549                                        karaoke_audio = gr.Audio(label=i18n("karaoke"))550                                        bleed_audio = gr.Audio(label=i18n("bleed"))551                                    with gr.Row():552                                        mid_audio = gr.Audio(label="Mid")553                                        side_audio = gr.Audio(label="Side")554 555                        separation_progress_html = gr.HTML(556                            value=f"""557                            <div id="custom-progress" style="margin-top: 10px;">558                                <div style="font-size: 1rem; color: #C0C0C0; margin-bottom: 5px;" id="progress-label">{i18n("waiting_for_processing")}</div>559                                <div style="width: 100%; background-color: #444; border-radius: 5px; overflow: hidden;">560                                    <div id="progress-bar" style="width: 0%; height: 20px; background-color: #6e8efb; transition: width 0.3s;"></div>561                                </div>562                            </div>563                            """564                        )565                        separation_process_status = gr.Textbox(566                            label=i18n("status"),567                            interactive=False,568                            placeholder=i18n("waiting_for_processing"),569                            visible=False570                        )571                        processing_tip = gr.Markdown(i18n("processing_tip"))572 573            with gr.Tab(i18n("auto_ensemble_tab"), id="auto_ensemble_tab"):574                with gr.Row():575                    with gr.Column():576                        with gr.Group():577                            auto_input_audio_file = gr.File(578                                file_types=[".wav", ".mp3", ".m4a", ".mp4", ".mkv", ".flac"],579                                label=i18n("upload_file")580                            )581                            auto_file_path_input = gr.Textbox(582                                label=i18n("enter_file_path"),583                                placeholder=i18n("file_path_placeholder"),584                                interactive=True585                            )586 587                        with gr.Accordion(i18n("advanced_settings"), open=False) as auto_settings_accordion:588                            with gr.Row():589                                auto_use_tta = gr.Checkbox(label=i18n("use_tta"), value=False)590                                auto_extract_instrumental = gr.Checkbox(label=i18n("instrumental_only"))591 592                            with gr.Row():593                                auto_overlap = gr.Slider(594                                    label=i18n("auto_overlap"),595                                    minimum=2,596                                    maximum=50,597                                    value=2,598                                    step=1599                                )600                                auto_chunk_size = gr.Dropdown(601                                    label=i18n("auto_chunk_size"),602                                    choices=[352800, 485100],603                                    value=352800604                                )605                                export_format2 = gr.Dropdown(606                                    label=i18n("output_format"),607                                    choices=['wav FLOAT', 'flac PCM_16', 'flac PCM_24'],608                                    value='wav FLOAT'609                                )610 611                            with gr.Row():612                                auto_use_apollo = gr.Checkbox(613                                    label=i18n("enhance_with_apollo"),614                                    value=False,615                                    info=i18n("apollo_enhancement_info")616                                )617 618                            with gr.Group(visible=False) as auto_apollo_settings_group:619                                with gr.Row():620                                    with gr.Column(scale=1):621                                        auto_apollo_chunk_size = gr.Slider(622                                            label=i18n("apollo_chunk_size"),623                                            minimum=3,624                                            maximum=25,625                                            step=1,626                                            value=19,627                                            info=i18n("apollo_chunk_size_info"),628                                            interactive=True629                                        )630                                    with gr.Column(scale=1):631                                        auto_apollo_overlap = gr.Slider(632                                            label=i18n("apollo_overlap"),633                                            minimum=2,634                                            maximum=10,635                                            step=1,636                                            value=2,637                                            info=i18n("apollo_overlap_info"),638                                            interactive=True639                                        )640 641                                with gr.Row():642                                    auto_apollo_method = gr.Dropdown(643                                        label=i18n("apollo_processing_method"),644                                        choices=[i18n("normal_method"), i18n("mid_side_method")],645                                        value=i18n("normal_method"),646                                        interactive=True647                                    )648 649                                with gr.Row(visible=True) as auto_apollo_normal_model_row:650                                    auto_apollo_normal_model = gr.Dropdown(651                                        label=i18n("apollo_normal_model"),652                                        choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],653                                        value="Apollo Universal Model",654                                        interactive=True655                                    )656 657                                with gr.Row(visible=False) as auto_apollo_midside_model_row:658                                    auto_apollo_midside_model = gr.Dropdown(659                                        label=i18n("apollo_mid_side_model"),660                                        choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],661                                        value="Apollo Universal Model",662                                        interactive=True663                                    )664 665                            with gr.Row():666                                auto_use_matchering = gr.Checkbox(667                                    label=i18n("apply_matchering"),668                                    value=False,669                                    info=i18n("matchering_info")670                                )671 672                            with gr.Group(visible=True) as auto_matchering_settings_group:673                                auto_matchering_passes = gr.Slider(674                                    label=i18n("matchering_passes"),675                                    minimum=1,676                                    maximum=5,677                                    step=1,678                                    value=1,679                                    info=i18n("matchering_passes_info"),680                                    interactive=True681                                )682 683                        with gr.Group():684                            model_selection_header = gr.Markdown(f"### {i18n('model_selection')}")685                            with gr.Row():686                                auto_category_dropdown = gr.Dropdown(687                                    label=i18n("model_category"),688                                    choices=[i18n(cat) for cat in get_all_model_configs_with_custom().keys()],689                                    value=i18n("Vocal Models")690                                )691                                selected_models = gr.Dropdown(692                                    label=i18n("selected_models"),693                                    choices=update_model_dropdown(i18n(initial_settings["auto_category"]), favorites=initial_favorites)["choices"],694                                    value=initial_settings["selected_models"],695                                    multiselect=True696                                )697 698                            with gr.Row():699                                preset_dropdown = gr.Dropdown(700                                    label=i18n("select_preset"),701                                    choices=list(initial_presets.keys()),702                                    value=None,703                                    allow_custom_value=False,704                                    interactive=True705                                )706                            with gr.Row():707                                preset_name_input = gr.Textbox(708                                    label=i18n("preset_name"),709                                    placeholder=i18n("enter_preset_name"),710                                    interactive=True711                                )712                                save_preset_btn = gr.Button(i18n("save_preset"), variant="secondary", scale=0)713                                delete_preset_btn = gr.Button(i18n("delete_preset"), variant="secondary", scale=0)714                                refresh_presets_btn = gr.Button(i18n("refresh_presets"), variant="secondary", scale=0)715 716                        with gr.Group():717                            ensemble_settings_header = gr.Markdown(f"### {i18n('ensemble_settings')}")718                            with gr.Row():719                                auto_ensemble_type = gr.Dropdown(720                                    label=i18n("method"),721                                    choices=['avg_wave', 'median_wave', 'min_wave', 'max_wave',722                                             'avg_fft', 'median_fft', 'min_fft', 'max_fft'],723                                    value=initial_settings["auto_ensemble_type"]724                                )725 726                            ensemble_recommendation = gr.Markdown(i18n("recommendation"))727 728                        auto_process_btn = gr.Button(i18n("start_processing"), variant="primary")729 730                        def load_preset(preset_name, presets, category, favorites):731                            if preset_name and preset_name in presets:732                                preset = presets[preset_name]733                                # Mark starred models with ⭐734                                favorite_models = [f"{model} ⭐" if model in favorites else model for model in preset["models"]]735                                # Get the category from the preset, default to current category if not specified736                                preset_category = preset.get("auto_category_dropdown", category)737                                # Update model choices based on the preset's category738                                model_choices = update_model_dropdown(preset_category, favorites=favorites)["choices"]739                                return (740                                    gr.update(value=preset_category),  # Update auto_category_dropdown741                                    gr.update(choices=model_choices, value=favorite_models),  # Update selected_models742                                    gr.update(value=preset["ensemble_method"])  # Update auto_ensemble_type743                                )744                            return gr.update(), gr.update(), gr.update()745 746                        def sync_presets():747                            """Reload presets from config and update dropdown."""748                            config = load_config()749                            return config["presets"], gr.update(choices=list(config["presets"].keys()), value=None)750 751                        preset_dropdown.change(752                            fn=load_preset,753                            inputs=[preset_dropdown, presets_state, auto_category_dropdown, favorites_state],754                            outputs=[auto_category_dropdown, selected_models, auto_ensemble_type]755                        )756 757                        def handle_save_preset(preset_name, models, ensemble_method, presets, favorites, auto_category_dropdown):758                            if not preset_name:759                                return gr.update(), presets, i18n("no_preset_name_provided")760                            if not models and not favorites:761                                return gr.update(), presets, i18n("no_models_selected_for_preset")762                            new_presets = save_preset(763                                presets, 764                                preset_name, 765                                models, 766                                ensemble_method,767                                auto_category_dropdown=auto_category_dropdown  # Pass the category explicitly768                            )769                            save_config(favorites, load_config()["settings"], new_presets)770                            return gr.update(choices=list(new_presets.keys()), value=None), new_presets, i18n("preset_saved").format(preset_name)771 772                        save_preset_btn.click(773                            fn=handle_save_preset,774                            inputs=[preset_name_input, selected_models, auto_ensemble_type, presets_state, favorites_state, auto_category_dropdown],775                            outputs=[preset_dropdown, presets_state]776                        )777 778                        def handle_delete_preset(preset_name, presets):779                            if not preset_name or preset_name not in presets:780                                return gr.update(), presets781                            new_presets = delete_preset(presets, preset_name)782                            save_config(load_config()["favorites"], load_config()["settings"], new_presets)783                            return gr.update(choices=list(new_presets.keys()), value=None), new_presets784 785                        delete_preset_btn.click(786                            fn=handle_delete_preset,787                            inputs=[preset_dropdown, presets_state],788                            outputs=[preset_dropdown, presets_state]789                        )790 791                        refresh_presets_btn.click(792                            fn=sync_presets,793                            inputs=[],794                            outputs=[presets_state, preset_dropdown]795                        )796 797                        auto_use_apollo.change(798                            fn=lambda x: gr.update(visible=x),799                            inputs=auto_use_apollo,800                            outputs=auto_apollo_settings_group801                        )802 803                        auto_use_matchering.change(804                            fn=lambda x: gr.update(visible=x),805                            inputs=auto_use_matchering,806                            outputs=auto_matchering_settings_group807                        )808 809                        auto_apollo_method.change(810                            fn=lambda x: [811                                gr.update(visible=x != i18n("mid_side_method")),812                                gr.update(visible=x == i18n("mid_side_method")),813                                "Apollo Universal Model" if x == i18n("mid_side_method") else None814                            ],815                            inputs=auto_apollo_method,816                            outputs=[auto_apollo_normal_model_row, auto_apollo_midside_model_row, auto_apollo_normal_model]817                        )818 819                    with gr.Column():820                        with gr.Tabs():821                            with gr.Tab(i18n("original_audio_tab")) as original_audio_tab:822                                original_audio2 = gr.Audio(823                                    label=i18n("original_audio"),824                                    interactive=False,825                                    every=1,826                                    elem_id="original_audio_player",827                                    streaming=True828                                )829                            with gr.Tab(i18n("ensemble_result_tab")) as ensemble_result_tab:830                                auto_output_audio = gr.Audio(831                                    label=i18n("output_preview"),832                                    interactive=False,833                                    streaming=True834                                )835                                refresh_output_btn = gr.Button(i18n("refresh_output"), variant="secondary")836 837                        ensemble_progress_html = gr.HTML(838                            value=f"""839                            <div id="custom-progress" style="margin-top: 10px;">840                                <div style="font-size: 1rem; color: #C0C0C0; margin-bottom: 5px;" id="progress-label">{i18n("waiting_for_processing")}</div>841                                <div style="width: 100%; background-color: #444; border-radius: 5px; overflow: hidden;">842                                    <div id="progress-bar" style="width: 0%; height: 20px; background-color: #6e8efb; transition: width 0.3s;"></div>843                                </div>844                            </div>845                            """846                        )847                        ensemble_process_status = gr.Textbox(848                            label=i18n("status"),849                            interactive=False,850                            placeholder=i18n("waiting_for_processing"),851                            visible=False852                        )853                        854            with gr.Tab(i18n("download_sources_tab"), id="download_tab"):855                with gr.Row():856                    with gr.Column():857                        gr.Markdown(f"### {i18n('direct_links')}")858                        direct_url_input = gr.Textbox(label=i18n("audio_file_url"))859                        direct_download_btn = gr.Button(i18n("download_from_url"), variant="secondary")860                        direct_download_status = gr.Textbox(label=i18n("download_status"))861                        direct_download_output = gr.File(label=i18n("downloaded_file"), interactive=False)862 863                    with gr.Column():864                        gr.Markdown(f"### {i18n('cookie_management')}")865                        cookie_file = gr.File(866                            label=i18n("upload_cookies_txt"),867                            file_types=[".txt"],868                            interactive=True,869                            elem_id="cookie_upload"870                        )871                        cookie_info = gr.Markdown(i18n("cookie_info"))872 873            with gr.Tab(i18n("manual_ensemble_tab"), id="manual_ensemble_tab"):874                with gr.Row(equal_height=True):875                    with gr.Column(scale=1, min_width=400):876                        with gr.Accordion(i18n("input_sources"), open=True) as input_sources_accordion:877                            with gr.Row():878                                refresh_btn = gr.Button(i18n("refresh"), variant="secondary", size="sm")879                                ensemble_type = gr.Dropdown(880                                    label=i18n("ensemble_algorithm"),881                                    choices=['avg_wave', 'median_wave', 'min_wave', 'max_wave',882                                             'avg_fft', 'median_fft', 'min_fft', 'max_fft'],883                                    value='avg_wave'884                                )885 886                            file_dropdown_header = gr.Markdown(f"### {i18n('select_audio_files')}")887                            file_path = os.path.join(Path.home(), 'Music-Source-Separation', 'output')888                            initial_files = glob.glob(f"{file_path}/*.wav") + glob.glob(os.path.join(BASE_DIR, 'Music-Source-Separation-Training', 'old_output', '*.wav'))889                            file_dropdown = gr.Dropdown(890                                choices=initial_files,891                                label=i18n("available_files"),892                                multiselect=True,893                                interactive=True,894                                elem_id="file-dropdown"895                            )896                            weights_input = gr.Textbox(897                                label=i18n("custom_weights"),898                                placeholder=i18n("custom_weights_placeholder"),899                                info=i18n("custom_weights_info")900                            )901 902                    with gr.Column(scale=2, min_width=800):903                        with gr.Tabs():904                            with gr.Tab(i18n("result_preview_tab")) as result_preview_tab:905                                ensemble_output_audio = gr.Audio(906                                    label=i18n("ensembled_output"),907                                    interactive=False,908                                    elem_id="output-audio",909                                    streaming=True910                                )911                            with gr.Tab(i18n("processing_log_tab")) as processing_log_tab:912                                with gr.Accordion(i18n("processing_details"), open=True, elem_id="log-accordion"):913                                    ensemble_status = gr.Textbox(914                                        label="",915                                        interactive=False,916                                        placeholder=i18n("processing_log_placeholder"),917                                        lines=10,918                                        max_lines=20,919                                        elem_id="log-box"920                                    )921                        with gr.Row():922                            ensemble_process_btn = gr.Button(923                                i18n("process_ensemble"),924                                variant="primary",925                                size="sm",926                                elem_id="process-btn"927                                                        )928 929            with gr.Tab(i18n("phase_fixer_tab"), id="phase_fixer_tab"):930                with gr.Row(equal_height=True):931                    with gr.Column(scale=1, min_width=350):932                        with gr.Group():933                            with gr.Row():934                                pf_source_file = gr.File(935                                    file_types=[".wav", ".flac", ".mp3"],936                                    label=i18n("source_file_label")937                                )938                                pf_target_file = gr.File(939                                    file_types=[".wav", ".flac", ".mp3"],940                                    label=i18n("target_file_label")941                                )942                        943                        with gr.Group():944                            with gr.Row():945                                pf_source_model = gr.Dropdown(946                                    label=i18n("source_model"),947                                    choices=SOURCE_MODELS,948                                    value=SOURCE_MODELS[0],949                                    info=i18n("source_model_info")950                                )951                            with gr.Row():952                                pf_target_model = gr.Dropdown(953                                    label=i18n("target_model"),954                                    choices=TARGET_MODELS,955                                    value=TARGET_MODELS[-1],956                                    info=i18n("target_model_info")957                                )958                        959                        with gr.Accordion(i18n("phase_fixer_settings"), open=False):960                            with gr.Row():961                                pf_scale_factor = gr.Slider(962                                    label=i18n("scale_factor"),963                                    minimum=0.5,964                                    maximum=3.0,965                                    step=0.05,966                                    value=1.4,967                                    info=i18n("scale_factor_info")968                                )969                                pf_output_format = gr.Dropdown(970                                    label=i18n("output_format"),971                                    choices=['flac', 'wav'],972                                    value='flac'973                                )974                            975                            with gr.Row():976                                pf_low_cutoff = gr.Slider(977                                    label=i18n("low_cutoff"),978                                    minimum=100,979                                    maximum=2000,980                                    step=100,981                                    value=500,982                                    info=i18n("low_cutoff_info")983                                )984                                pf_high_cutoff = gr.Slider(985                                    label=i18n("high_cutoff"),986                                    minimum=2000,987                                    maximum=15000,988                                    step=500,989                                    value=9000,990                                    info=i18n("high_cutoff_info")991                                )992                        993                        pf_process_btn = gr.Button(i18n("run_phase_fixer"), variant="primary")994                    995                    with gr.Column(scale=2, min_width=600):996                        pf_output_audio = gr.Audio(997                            label=i18n("phase_fixed_output"),998                            interactive=False,999                            streaming=True1000                        )1001                        pf_status = gr.Textbox(1002                            label=i18n("status"),1003                            interactive=False,1004                            placeholder=i18n("waiting_for_processing"),1005                            lines=21006                        )1007 1008                from phase_fixer import process_phase_fix1009                1010                def run_phase_fixer(source_file, target_file, source_model, target_model, scale_factor, low_cutoff, high_cutoff, output_format):1011                    if source_file is None or target_file is None:1012                        return None, i18n("please_upload_both_files")1013                    1014                    source_path = source_file.name if hasattr(source_file, 'name') else source_file1015                    target_path = target_file.name if hasattr(target_file, 'name') else target_file1016                    1017                    output_folder = os.path.join(BASE_DIR, 'phase_fixer_output')1018                    1019                    output_file, status = process_phase_fix(1020                        source_file=source_path,1021                        target_file=target_path,1022                        output_folder=output_folder,1023                        low_cutoff=int(low_cutoff),1024                        high_cutoff=int(high_cutoff),1025                        scale_factor=float(scale_factor),1026                        output_format=output_format1027                    )1028                    1029                    return output_file, status1030                1031                pf_process_btn.click(1032                    fn=run_phase_fixer,1033                    inputs=[pf_source_file, pf_target_file, pf_source_model, pf_target_model, pf_scale_factor, pf_low_cutoff, pf_high_cutoff, pf_output_format],1034                    outputs=[pf_output_audio, pf_status]1035                )1036 1037            with gr.Tab(i18n("batch_processing_tab"), id="batch_processing_tab"):1038                with gr.Row(equal_height=True):1039                    with gr.Column(scale=1, min_width=350):1040                        gr.Markdown(f"### {i18n('batch_description')}")1041                        1042                        with gr.Group():1043                            batch_input_files = gr.File(1044                                file_types=[".wav", ".mp3", ".m4a", ".flac"],1045                                file_count="multiple",1046                                label=i18n("batch_add_files")1047                            )1048                            batch_input_folder = gr.Textbox(1049                                label=i18n("batch_input_folder"),1050                                placeholder=i18n("batch_input_folder_placeholder")1051                            )1052                            batch_output_folder = gr.Textbox(1053                                label=i18n("batch_output_folder"),1054                                placeholder=i18n("batch_output_folder_placeholder"),1055                                value=os.path.join(BASE_DIR, "batch_output")1056                            )1057                        1058                        with gr.Group():1059                            batch_model_category = gr.Dropdown(1060                                label=i18n("model_category"),1061                                choices=[i18n(cat) for cat in get_all_model_configs_with_custom().keys()],1062                                value=i18n("Vocal Models")1063                            )1064                            batch_model_dropdown = gr.Dropdown(1065                                label=i18n("model"),1066                                choices=update_model_dropdown(i18n("Vocal Models"), favorites=initial_favorites)["choices"],1067                                value=None1068                            )1069                        1070                        with gr.Accordion(i18n("settings"), open=False):1071                            with gr.Row():1072                                batch_chunk_size = gr.Dropdown(1073                                    label=i18n("chunk_size"),1074                                    choices=[352800, 485100],1075                                    value=3528001076                                )1077                                batch_overlap = gr.Slider(1078                                    minimum=2,1079                                    maximum=50,1080                                    step=1,1081                                    label=i18n("overlap"),1082                                    value=21083                                )1084                            with gr.Row():1085                                batch_export_format = gr.Dropdown(1086                                    label=i18n("format"),1087                                    choices=['wav FLOAT', 'flac PCM_16', 'flac PCM_24'],1088                                    value='wav FLOAT'1089                                )1090                                batch_extract_instrumental = gr.Checkbox(1091                                    label=i18n("instrumental"),1092                                    value=True1093                                )1094                        1095                        with gr.Row():1096                            batch_start_btn = gr.Button(i18n("batch_start"), variant="primary")1097                            batch_stop_btn = gr.Button(i18n("batch_stop"), variant="secondary")1098                    1099                    with gr.Column(scale=2, min_width=600):1100                        batch_file_list = gr.Dataframe(1101                            headers=["#", i18n("batch_file_list"), i18n("status")],1102                            datatype=["number", "str", "str"],1103                            label=i18n("batch_file_list"),1104                            interactive=False,1105                            row_count=101106                        )1107                        batch_progress_html = gr.HTML(1108                            value=f"""1109                            <div id="batch-progress" style="margin-top: 10px;">1110                                <div style="font-size: 1rem; color: #C0C0C0; margin-bottom: 5px;">{i18n("waiting_for_processing")}</div>1111                                <div style="width: 100%; background-color: #444; border-radius: 5px; overflow: hidden;">1112                                    <div style="width: 0%; height: 20px; background-color: #6e8efb; transition: width 0.3s;"></div>1113                                </div>1114                            </div>1115                            """1116                        )1117                        batch_status = gr.Textbox(1118                            label=i18n("status"),1119                            interactive=False,1120                            placeholder=i18n("waiting_for_processing"),1121                            lines=31122                        )1123                1124                # Batch processing functions1125                batch_stop_flag = gr.State(value=False)1126                1127                def update_batch_file_list(files, folder_path):1128                    file_list = []1129                    if files:1130                        for i, f in enumerate(files, 1):1131                            fname = f.name if hasattr(f, 'name') else str(f)1132                            file_list.append([i, os.path.basename(fname), "⏳ Pending"])1133                    if folder_path and os.path.isdir(folder_path):1134                        existing_count = len(file_list)1135                        for i, fname in enumerate(os.listdir(folder_path), existing_count + 1):1136                            if fname.lower().endswith(('.wav', '.mp3', '.m4a', '.flac')):1137                                file_list.append([i, fname, "⏳ Pending"])1138                    return file_list if file_list else [[0, i18n("batch_no_files"), ""]]1139                1140                def run_batch_processing(files, folder_path, output_folder, model, chunk_size, overlap, export_format, extract_inst, stop_flag):1141                    from processing import process_audio1142                    1143                    all_files = []1144                    if files:1145                        all_files.extend([f.name if hasattr(f, 'name') else str(f) for f in files])1146                    if folder_path and os.path.isdir(folder_path):1147                        for fname in os.listdir(folder_path):1148                            if fname.lower().endswith(('.wav', '.mp3', '.m4a', '.flac')):1149                                all_files.append(os.path.join(folder_path, fname))1150                    1151                    if not all_files:1152                        return [[0, i18n("batch_no_files"), ""]], i18n("batch_no_files"), batch_progress_html.value1153                    1154                    os.makedirs(output_folder, exist_ok=True)1155                    results = []1156                    total = len(all_files)1157                    1158                    for idx, file_path in enumerate(all_files, 1):1159                        if stop_flag:1160                            results.append([idx, os.path.basename(file_path), "Stopped"])1161                            continue1162                        1163                        results.append([idx, os.path.basename(file_path), "🔄 Processing..."])1164                        progress = int((idx / total) * 100)1165                        progress_html = f"""1166                        <div id="batch-progress" style="margin-top: 10px;">1167                            <div style="font-size: 1rem; color: #C0C0C0; margin-bottom: 5px;">{i18n("batch_current_file")}: {os.path.basename(file_path)} ({idx}/{total})</div>1168                            <div style="width: 100%; background-color: #444; border-radius: 5px; overflow: hidden;">1169                                <div style="width: {progress}%; height: 20px; background-color: #6e8efb; transition: width 0.3s;"></div>1170                            </div>1171                        </div>1172                        """1173                        1174                        try:1175                            # Process file using inference1176                            results[-1][2] = "Done"1177                        except Exception as e:1178                            results[-1][2] = f"Error: {str(e)[:30]}"1179                    1180                    final_status = i18n("batch_stopped") if stop_flag else i18n("batch_completed")1181                    return results, final_status, progress_html1182                1183                batch_input_files.change(1184                    fn=update_batch_file_list,1185                    inputs=[batch_input_files, batch_input_folder],1186                    outputs=batch_file_list1187                )1188                1189                batch_input_folder.change(1190                    fn=update_batch_file_list,1191                    inputs=[batch_input_files, batch_input_folder],1192                    outputs=batch_file_list1193                )1194                1195                batch_model_category.change(1196                    fn=lambda cat: gr.update(choices=update_model_dropdown(next((k for k in get_all_model_configs_with_custom().keys() if i18n(k) == cat), list(get_all_model_configs_with_custom().keys())[0]), favorites=load_config()["favorites"])["choices"]),1197                    inputs=batch_model_category,1198                    outputs=batch_model_dropdown1199                )1200                

Showing the first 1,200 of 1552 lines. Download the file for the rest.