Update gui.py
Browse files
gui.py
CHANGED
|
@@ -1,958 +1,100 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
import glob
|
| 4 |
-
import subprocess
|
| 5 |
-
from pathlib import Path
|
| 6 |
-
from datetime import datetime
|
| 7 |
import json
|
| 8 |
-
import sys
|
| 9 |
-
import time
|
| 10 |
-
import random
|
| 11 |
-
from helpers import update_model_dropdown, handle_file_upload, clear_old_output, save_uploaded_file, update_file_list, clean_model
|
| 12 |
-
from download import download_callback
|
| 13 |
-
from model import get_model_config, MODEL_CONFIGS
|
| 14 |
-
from processing import process_audio, auto_ensemble_process, ensemble_audio_fn, refresh_auto_output
|
| 15 |
-
from assets.i18n.i18n import I18nAuto
|
| 16 |
-
from config_manager import load_config, save_config, update_favorites, save_preset, delete_preset
|
| 17 |
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
logging.basicConfig(filename='sesa_gui.log', level=logging.DEBUG)
|
| 20 |
|
| 21 |
-
# BASE_DIR
|
| 22 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 23 |
CONFIG_DIR = os.path.join(BASE_DIR, "assets")
|
| 24 |
CONFIG_FILE = os.path.join(CONFIG_DIR, "config.json")
|
| 25 |
-
URL_FILE = os.path.join(CONFIG_DIR, "last_url.txt")
|
| 26 |
|
| 27 |
-
# Load user config
|
| 28 |
user_config = load_config()
|
| 29 |
initial_settings = user_config["settings"]
|
| 30 |
initial_favorites = user_config["favorites"]
|
| 31 |
-
initial_presets = user_config["presets"]
|
| 32 |
-
|
| 33 |
-
# Ensure auto_category is valid
|
| 34 |
-
if "auto_category" not in initial_settings or initial_settings["auto_category"] not in MODEL_CONFIGS:
|
| 35 |
-
initial_settings["auto_category"] = "Vocal Models"
|
| 36 |
-
|
| 37 |
-
# Create config file if it doesn't exist
|
| 38 |
-
if 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)
|
| 45 |
-
}
|
| 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)
|
| 50 |
-
else:
|
| 51 |
-
try:
|
| 52 |
-
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
|
| 53 |
-
config = json.load(f)
|
| 54 |
-
if "lang" not in config:
|
| 55 |
-
config["lang"] = {"override": False, "selected_lang": "auto"}
|
| 56 |
-
if "sharing" not in config:
|
| 57 |
-
config["sharing"] = {
|
| 58 |
-
"method": "gradio",
|
| 59 |
-
"ngrok_token": "",
|
| 60 |
-
"port": random.randint(1000, 9000)
|
| 61 |
-
}
|
| 62 |
-
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
| 63 |
-
json.dump(config, f, indent=2)
|
| 64 |
-
except json.JSONDecodeError:
|
| 65 |
-
print("Warning: config.json is corrupted. Creating a new one.")
|
| 66 |
-
default_config = {
|
| 67 |
-
"lang": {"override": False, "selected_lang": "auto"},
|
| 68 |
-
"sharing": {
|
| 69 |
-
"method": "gradio",
|
| 70 |
-
"ngrok_token": "",
|
| 71 |
-
"port": random.randint(1000, 9000)
|
| 72 |
-
}
|
| 73 |
-
}
|
| 74 |
-
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
| 75 |
-
json.dump(default_config, f, indent=2)
|
| 76 |
|
| 77 |
# Initialize I18nAuto
|
| 78 |
i18n = I18nAuto()
|
| 79 |
|
| 80 |
-
# Output formats
|
| 81 |
-
OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
|
| 82 |
-
|
| 83 |
-
# Interface creation function
|
| 84 |
def create_interface():
|
| 85 |
css = """
|
| 86 |
-
body {
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
margin: 0;
|
| 91 |
-
padding: 1rem;
|
| 92 |
-
font-family: 'Poppins', sans-serif;
|
| 93 |
-
color: #C0C0C0;
|
| 94 |
-
overflow-x: hidden;
|
| 95 |
-
}
|
| 96 |
-
.header-text {
|
| 97 |
-
text-align: center;
|
| 98 |
-
padding: 100px 20px 20px;
|
| 99 |
-
color: #ff4040;
|
| 100 |
-
font-size: 3rem;
|
| 101 |
-
font-weight: 900;
|
| 102 |
-
text-shadow: 0 0 10px rgba(255, 64, 64, 0.5);
|
| 103 |
-
z-index: 1500;
|
| 104 |
-
animation: text-glow 2s infinite;
|
| 105 |
-
}
|
| 106 |
-
.header-subtitle {
|
| 107 |
-
text-align: center;
|
| 108 |
-
color: #C0C0C0;
|
| 109 |
-
font-size: 1.2rem;
|
| 110 |
-
font-weight: 300;
|
| 111 |
-
margin-top: -10px;
|
| 112 |
-
text-shadow: 0 0 5px rgba(255, 64, 64, 0.3);
|
| 113 |
-
}
|
| 114 |
-
.gr-tab {
|
| 115 |
-
background: rgba(128, 0, 0, 0.5) !important;
|
| 116 |
-
border-radius: 12px 12px 0 0 !important;
|
| 117 |
-
margin: 0 5px !important;
|
| 118 |
-
color: #C0C0C0 !important;
|
| 119 |
-
border: 1px solid #ff4040 !important;
|
| 120 |
-
z-index: 1500;
|
| 121 |
-
transition: background 0.3s ease, color 0.3s ease;
|
| 122 |
-
padding: 10px 20px !important;
|
| 123 |
-
font-size: 1.1rem !important;
|
| 124 |
-
}
|
| 125 |
-
button {
|
| 126 |
-
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
|
| 127 |
-
background: #800000 !important;
|
| 128 |
-
border: 1px solid #ff4040 !important;
|
| 129 |
-
color: #C0C0C0 !important;
|
| 130 |
-
border-radius: 8px !important;
|
| 131 |
-
padding: 8px 16px !important;
|
| 132 |
-
box-shadow: 0 2px 10px rgba(255, 64, 64, 0.3);
|
| 133 |
-
}
|
| 134 |
-
button:hover {
|
| 135 |
-
transform: scale(1.05) !important;
|
| 136 |
-
box-shadow: 0 10px 40px rgba(255, 64, 64, 0.7) !important;
|
| 137 |
-
background: #ff4040 !important;
|
| 138 |
-
}
|
| 139 |
-
.compact-upload.horizontal {
|
| 140 |
-
display: inline-flex !important;
|
| 141 |
-
align-items: center !important;
|
| 142 |
-
gap: 8px !important;
|
| 143 |
-
max-width: 400px !important;
|
| 144 |
-
height: 40px !important;
|
| 145 |
-
padding: 0 12px !important;
|
| 146 |
-
border: 1px solid #ff4040 !important;
|
| 147 |
-
background: rgba(128, 0, 0, 0.5) !important;
|
| 148 |
-
border-radius: 8px !important;
|
| 149 |
-
}
|
| 150 |
-
.compact-dropdown {
|
| 151 |
-
--padding: 8px 12px !important;
|
| 152 |
-
--radius: 10px !important;
|
| 153 |
-
border: 1px solid #ff4040 !important;
|
| 154 |
-
background: rgba(128, 0, 0, 0.5) !important;
|
| 155 |
-
color: #C0C0C0 !important;
|
| 156 |
-
}
|
| 157 |
-
#custom-progress {
|
| 158 |
-
margin-top: 10px;
|
| 159 |
-
padding: 10px;
|
| 160 |
-
background: rgba(128, 0, 0, 0.3);
|
| 161 |
-
border-radius: 8px;
|
| 162 |
-
border: 1px solid #ff4040;
|
| 163 |
-
}
|
| 164 |
-
#progress-bar {
|
| 165 |
-
height: 20px;
|
| 166 |
-
background: linear-gradient(to right, #6e8efb, #ff4040);
|
| 167 |
-
border-radius: 5px;
|
| 168 |
-
transition: width 0.5s ease-in-out;
|
| 169 |
-
max-width: 100% !important;
|
| 170 |
-
}
|
| 171 |
-
.gr-accordion {
|
| 172 |
-
background: rgba(128, 0, 0, 0.5) !important;
|
| 173 |
-
border-radius: 10px !important;
|
| 174 |
-
border: 1px solid #ff4040 !important;
|
| 175 |
-
}
|
| 176 |
-
.footer {
|
| 177 |
-
text-align: center;
|
| 178 |
-
padding: 20px;
|
| 179 |
-
color: #ff4040;
|
| 180 |
-
font-size: 14px;
|
| 181 |
-
margin-top: 40px;
|
| 182 |
-
background: rgba(128, 0, 0, 0.3);
|
| 183 |
-
border-top: 1px solid #ff4040;
|
| 184 |
-
}
|
| 185 |
-
#log-accordion {
|
| 186 |
-
max-height: 400px;
|
| 187 |
-
overflow-y: auto;
|
| 188 |
-
background: rgba(0, 0, 0, 0.7) !important;
|
| 189 |
-
padding: 10px;
|
| 190 |
-
border-radius: 8px;
|
| 191 |
-
}
|
| 192 |
-
@keyframes text-glow {
|
| 193 |
-
0% { text-shadow: 0 0 5px rgba(192, 192, 192, 0); }
|
| 194 |
-
50% { text-shadow: 0 0 15px rgba(192, 192, 192, 1); }
|
| 195 |
-
100% { text-shadow: 0 0 5px rgba(192, 192, 192, 0); }
|
| 196 |
-
}
|
| 197 |
"""
|
| 198 |
|
| 199 |
-
# Load user config
|
| 200 |
-
user_config = load_config()
|
| 201 |
-
initial_settings = user_config["settings"]
|
| 202 |
-
initial_favorites = user_config["favorites"]
|
| 203 |
-
initial_presets = user_config["presets"]
|
| 204 |
-
|
| 205 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 206 |
-
#
|
| 207 |
-
current_lang = gr.Textbox(value=i18n.language, visible=False)
|
| 208 |
favorites_state = gr.Textbox(value=json.dumps(initial_favorites), visible=False)
|
| 209 |
-
presets_state = gr.Textbox(value=json.dumps(initial_presets), visible=False)
|
| 210 |
-
|
| 211 |
-
header_html = gr.HTML(
|
| 212 |
-
value=f"""
|
| 213 |
-
<div class="header-text">{i18n("SESA Audio Separation")}</div>
|
| 214 |
-
<div class="header-subtitle">{i18n("ultimate_audio_separation")}</div>
|
| 215 |
-
"""
|
| 216 |
-
)
|
| 217 |
-
|
| 218 |
-
with gr.Tabs():
|
| 219 |
-
with gr.Tab(i18n("audio_separation_tab"), id="separation_tab"):
|
| 220 |
-
with gr.Row(equal_height=True):
|
| 221 |
-
with gr.Column(scale=1, min_width=380):
|
| 222 |
-
with gr.Accordion(i18n("input_model"), open=True):
|
| 223 |
-
with gr.Tabs():
|
| 224 |
-
with gr.Tab(i18n("upload")):
|
| 225 |
-
input_audio_file = gr.File(
|
| 226 |
-
file_types=[".wav", ".mp3", ".m4a", ".mp4", ".mkv", ".flac"],
|
| 227 |
-
elem_classes=["compact-upload", "horizontal"],
|
| 228 |
-
label=i18n("upload_file")
|
| 229 |
-
)
|
| 230 |
-
with gr.Tab(i18n("path")):
|
| 231 |
-
file_path_input = gr.Textbox(placeholder=i18n("path_placeholder"), label=i18n("file_path"))
|
| 232 |
-
|
| 233 |
-
with gr.Row():
|
| 234 |
-
model_category = gr.Dropdown(
|
| 235 |
-
label=i18n("category"),
|
| 236 |
-
choices=[i18n(cat) for cat in MODEL_CONFIGS.keys()],
|
| 237 |
-
value=i18n(initial_settings["model_category"])
|
| 238 |
-
)
|
| 239 |
-
favorite_button = gr.Button(i18n("add_favorite"), variant="secondary", scale=0)
|
| 240 |
-
|
| 241 |
-
model_dropdown = gr.Dropdown(
|
| 242 |
-
label=i18n("model"),
|
| 243 |
-
choices=update_model_dropdown(i18n(initial_settings["model_category"]), favorites=initial_favorites)["choices"],
|
| 244 |
-
value=initial_settings["selected_model"]
|
| 245 |
-
)
|
| 246 |
-
|
| 247 |
-
with gr.Accordion(i18n("settings"), open=False):
|
| 248 |
-
with gr.Row():
|
| 249 |
-
export_format = gr.Dropdown(
|
| 250 |
-
label=i18n("format"),
|
| 251 |
-
choices=['wav FLOAT', 'flac PCM_16', 'flac PCM_24'],
|
| 252 |
-
value=initial_settings["export_format"]
|
| 253 |
-
)
|
| 254 |
-
chunk_size = gr.Dropdown(
|
| 255 |
-
label=i18n("chunk_size"),
|
| 256 |
-
choices=[352800, 485100],
|
| 257 |
-
value=initial_settings["chunk_size"],
|
| 258 |
-
info=i18n("chunk_size_info")
|
| 259 |
-
)
|
| 260 |
-
|
| 261 |
-
overlap = gr.Slider(
|
| 262 |
-
minimum=2,
|
| 263 |
-
maximum=50,
|
| 264 |
-
step=1,
|
| 265 |
-
label=i18n("overlap"),
|
| 266 |
-
value=initial_settings["overlap"],
|
| 267 |
-
info=i18n("overlap_info")
|
| 268 |
-
)
|
| 269 |
-
|
| 270 |
-
use_tta = gr.Checkbox(
|
| 271 |
-
label=i18n("tta_boost"),
|
| 272 |
-
info=i18n("tta_info"),
|
| 273 |
-
value=initial_settings["use_tta"]
|
| 274 |
-
)
|
| 275 |
-
|
| 276 |
-
use_demud_phaseremix_inst = gr.Checkbox(
|
| 277 |
-
label=i18n("phase_fix"),
|
| 278 |
-
info=i18n("phase_fix_info"),
|
| 279 |
-
value=initial_settings["use_demud_phaseremix_inst"]
|
| 280 |
-
)
|
| 281 |
-
|
| 282 |
-
extract_instrumental = gr.Checkbox(
|
| 283 |
-
label=i18n("instrumental"),
|
| 284 |
-
info=i18n("instrumental_info"),
|
| 285 |
-
value=initial_settings["extract_instrumental"]
|
| 286 |
-
)
|
| 287 |
-
|
| 288 |
-
use_apollo = gr.Checkbox(
|
| 289 |
-
label=i18n("enhance_with_apollo"),
|
| 290 |
-
value=initial_settings["use_apollo"],
|
| 291 |
-
info=i18n("apollo_enhancement_info")
|
| 292 |
-
)
|
| 293 |
-
|
| 294 |
-
with gr.Group(visible=initial_settings["use_apollo"]) as apollo_settings_group:
|
| 295 |
-
with gr.Row():
|
| 296 |
-
apollo_chunk_size = gr.Slider(
|
| 297 |
-
label=i18n("apollo_chunk_size"),
|
| 298 |
-
minimum=3,
|
| 299 |
-
maximum=25,
|
| 300 |
-
step=1,
|
| 301 |
-
value=initial_settings["apollo_chunk_size"],
|
| 302 |
-
info=i18n("apollo_chunk_size_info")
|
| 303 |
-
)
|
| 304 |
-
apollo_overlap = gr.Slider(
|
| 305 |
-
label=i18n("apollo_overlap"),
|
| 306 |
-
minimum=2,
|
| 307 |
-
maximum=10,
|
| 308 |
-
step=1,
|
| 309 |
-
value=initial_settings["apollo_overlap"],
|
| 310 |
-
info=i18n("apollo_overlap_info")
|
| 311 |
-
)
|
| 312 |
-
|
| 313 |
-
apollo_method = gr.Dropdown(
|
| 314 |
-
label=i18n("apollo_processing_method"),
|
| 315 |
-
choices=[i18n("normal_method"), i18n("mid_side_method")],
|
| 316 |
-
value=i18n(initial_settings["apollo_method"])
|
| 317 |
-
)
|
| 318 |
-
|
| 319 |
-
apollo_normal_model_row = gr.Row(visible=initial_settings["apollo_method"] != "mid_side_method")
|
| 320 |
-
apollo_normal_model = gr.Dropdown(
|
| 321 |
-
label=i18n("apollo_normal_model"),
|
| 322 |
-
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
|
| 323 |
-
value=initial_settings["apollo_normal_model"],
|
| 324 |
-
container=apollo_normal_model_row
|
| 325 |
-
)
|
| 326 |
-
|
| 327 |
-
apollo_midside_model_row = gr.Row(visible=initial_settings["apollo_method"] == "mid_side_method")
|
| 328 |
-
apollo_midside_model = gr.Dropdown(
|
| 329 |
-
label=i18n("apollo_mid_side_model"),
|
| 330 |
-
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
|
| 331 |
-
value=initial_settings["apollo_midside_model"],
|
| 332 |
-
container=apollo_midside_model_row
|
| 333 |
-
)
|
| 334 |
-
|
| 335 |
-
use_matchering = gr.Checkbox(
|
| 336 |
-
label=i18n("apply_matchering"),
|
| 337 |
-
value=initial_settings.get("use_matchering", False),
|
| 338 |
-
info=i18n("matchering_info")
|
| 339 |
-
)
|
| 340 |
-
|
| 341 |
-
with gr.Group(visible=initial_settings.get("use_matchering", True)) as matchering_settings_group:
|
| 342 |
-
matchering_passes = gr.Slider(
|
| 343 |
-
label=i18n("matchering_passes"),
|
| 344 |
-
minimum=1,
|
| 345 |
-
maximum=5,
|
| 346 |
-
step=1,
|
| 347 |
-
value=initial_settings.get("matchering_passes", 1),
|
| 348 |
-
info=i18n("matchering_passes_info")
|
| 349 |
-
)
|
| 350 |
-
|
| 351 |
-
with gr.Row():
|
| 352 |
-
process_btn = gr.Button(i18n("process"), variant="primary")
|
| 353 |
-
clear_old_output_btn = gr.Button(i18n("reset"), variant="secondary")
|
| 354 |
-
clear_old_output_status = gr.Textbox(label=i18n("status"), interactive=False)
|
| 355 |
-
|
| 356 |
-
with gr.Column(scale=2, min_width=800):
|
| 357 |
-
with gr.Tabs():
|
| 358 |
-
with gr.Tab(i18n("main_tab")):
|
| 359 |
-
original_audio = gr.Audio(label=i18n("original"), interactive=True)
|
| 360 |
-
with gr.Row():
|
| 361 |
-
vocals_audio = gr.Audio(label=i18n("vocals"), show_download_button=True)
|
| 362 |
-
instrumental_audio = gr.Audio(label=i18n("instrumental_output"), show_download_button=True)
|
| 363 |
-
other_audio = gr.Audio(label=i18n("other"), show_download_button=True)
|
| 364 |
-
|
| 365 |
-
with gr.Tab(i18n("details_tab")):
|
| 366 |
-
with gr.Row():
|
| 367 |
-
male_audio = gr.Audio(label=i18n("male"))
|
| 368 |
-
female_audio = gr.Audio(label=i18n("female"))
|
| 369 |
-
speech_audio = gr.Audio(label=i18n("speech"))
|
| 370 |
-
with gr.Row():
|
| 371 |
-
drum_audio = gr.Audio(label=i18n("drums"))
|
| 372 |
-
bass_audio = gr.Audio(label=i18n("bass"))
|
| 373 |
-
with gr.Row():
|
| 374 |
-
effects_audio = gr.Audio(label=i18n("effects"))
|
| 375 |
-
|
| 376 |
-
with gr.Tab(i18n("advanced_tab")):
|
| 377 |
-
with gr.Row():
|
| 378 |
-
phaseremix_audio = gr.Audio(label=i18n("phase_remix"))
|
| 379 |
-
dry_audio = gr.Audio(label=i18n("dry"))
|
| 380 |
-
with gr.Row():
|
| 381 |
-
music_audio = gr.Audio(label=i18n("music"))
|
| 382 |
-
karaoke_audio = gr.Audio(label=i18n("karaoke"))
|
| 383 |
-
bleed_audio = gr.Audio(label=i18n("bleed"))
|
| 384 |
-
|
| 385 |
-
separation_progress_html = gr.HTML(
|
| 386 |
-
value=f"""
|
| 387 |
-
<div id="custom-progress">
|
| 388 |
-
<div id="progress-label">{i18n("waiting_for_processing")}</div>
|
| 389 |
-
<div style="width: 100%; background-color: #444; border-radius: 5px;">
|
| 390 |
-
<div id="progress-bar" style="width: 0%;"></div>
|
| 391 |
-
</div>
|
| 392 |
-
</div>
|
| 393 |
-
"""
|
| 394 |
-
)
|
| 395 |
-
separation_process_status = gr.Textbox(
|
| 396 |
-
label=i18n("status"),
|
| 397 |
-
interactive=False,
|
| 398 |
-
placeholder=i18n("waiting_for_processing"),
|
| 399 |
-
visible=False
|
| 400 |
-
)
|
| 401 |
-
processing_tip = gr.Markdown(i18n("processing_tip"))
|
| 402 |
-
|
| 403 |
-
with gr.Tab(i18n("auto_ensemble_tab"), id="auto_ensemble_tab"):
|
| 404 |
-
with gr.Row():
|
| 405 |
-
with gr.Column():
|
| 406 |
-
with gr.Group():
|
| 407 |
-
auto_input_audio_file = gr.File(
|
| 408 |
-
file_types=[".wav", ".mp3", ".m4a", ".mp4", ".mkv", ".flac"],
|
| 409 |
-
label=i18n("upload_file")
|
| 410 |
-
)
|
| 411 |
-
auto_file_path_input = gr.Textbox(
|
| 412 |
-
label=i18n("enter_file_path"),
|
| 413 |
-
placeholder=i18n("file_path_placeholder")
|
| 414 |
-
)
|
| 415 |
-
|
| 416 |
-
with gr.Accordion(i18n("advanced_settings"), open=False):
|
| 417 |
-
with gr.Row():
|
| 418 |
-
auto_use_tta = gr.Checkbox(label=i18n("use_tta"), value=False)
|
| 419 |
-
auto_extract_instrumental = gr.Checkbox(label=i18n("instrumental_only"))
|
| 420 |
-
|
| 421 |
-
with gr.Row():
|
| 422 |
-
auto_overlap = gr.Slider(
|
| 423 |
-
label=i18n("auto_overlap"),
|
| 424 |
-
minimum=2,
|
| 425 |
-
maximum=50,
|
| 426 |
-
value=2,
|
| 427 |
-
step=1
|
| 428 |
-
)
|
| 429 |
-
auto_chunk_size = gr.Dropdown(
|
| 430 |
-
label=i18n("auto_chunk_size"),
|
| 431 |
-
choices=[352800, 485100],
|
| 432 |
-
value=352800
|
| 433 |
-
)
|
| 434 |
-
export_format2 = gr.Dropdown(
|
| 435 |
-
label=i18n("output_format"),
|
| 436 |
-
choices=['wav FLOAT', 'flac PCM_16', 'flac PCM_24'],
|
| 437 |
-
value='wav FLOAT'
|
| 438 |
-
)
|
| 439 |
-
|
| 440 |
-
auto_use_apollo = gr.Checkbox(
|
| 441 |
-
label=i18n("enhance_with_apollo"),
|
| 442 |
-
value=False,
|
| 443 |
-
info=i18n("apollo_enhancement_info")
|
| 444 |
-
)
|
| 445 |
-
|
| 446 |
-
with gr.Group(visible=False) as auto_apollo_settings_group:
|
| 447 |
-
with gr.Row():
|
| 448 |
-
auto_apollo_chunk_size = gr.Slider(
|
| 449 |
-
label=i18n("apollo_chunk_size"),
|
| 450 |
-
minimum=3,
|
| 451 |
-
maximum=25,
|
| 452 |
-
step=1,
|
| 453 |
-
value=19,
|
| 454 |
-
info=i18n("apollo_chunk_size_info")
|
| 455 |
-
)
|
| 456 |
-
auto_apollo_overlap = gr.Slider(
|
| 457 |
-
label=i18n("apollo_overlap"),
|
| 458 |
-
minimum=2,
|
| 459 |
-
maximum=10,
|
| 460 |
-
step=1,
|
| 461 |
-
value=2,
|
| 462 |
-
info=i18n("apollo_overlap_info")
|
| 463 |
-
)
|
| 464 |
-
|
| 465 |
-
auto_apollo_method = gr.Dropdown(
|
| 466 |
-
label=i18n("apollo_processing_method"),
|
| 467 |
-
choices=[i18n("normal_method"), i18n("mid_side_method")],
|
| 468 |
-
value=i18n("normal_method")
|
| 469 |
-
)
|
| 470 |
-
|
| 471 |
-
auto_apollo_normal_model_row = gr.Row(visible=True)
|
| 472 |
-
auto_apollo_normal_model = gr.Dropdown(
|
| 473 |
-
label=i18n("apollo_normal_model"),
|
| 474 |
-
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
|
| 475 |
-
value="Apollo Universal Model",
|
| 476 |
-
container=auto_apollo_normal_model_row
|
| 477 |
-
)
|
| 478 |
-
|
| 479 |
-
auto_apollo_midside_model_row = gr.Row(visible=False)
|
| 480 |
-
auto_apollo_midside_model = gr.Dropdown(
|
| 481 |
-
label=i18n("apollo_mid_side_model"),
|
| 482 |
-
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
|
| 483 |
-
value="Apollo Universal Model",
|
| 484 |
-
container=auto_apollo_midside_model_row
|
| 485 |
-
)
|
| 486 |
-
|
| 487 |
-
auto_use_matchering = gr.Checkbox(
|
| 488 |
-
label=i18n("apply_matchering"),
|
| 489 |
-
value=False,
|
| 490 |
-
info=i18n("matchering_info")
|
| 491 |
-
)
|
| 492 |
-
|
| 493 |
-
with gr.Group(visible=False) as auto_matchering_settings_group:
|
| 494 |
-
auto_matchering_passes = gr.Slider(
|
| 495 |
-
label=i18n("matchering_passes"),
|
| 496 |
-
minimum=1,
|
| 497 |
-
maximum=5,
|
| 498 |
-
step=1,
|
| 499 |
-
value=1,
|
| 500 |
-
info=i18n("matchering_passes_info")
|
| 501 |
-
)
|
| 502 |
-
|
| 503 |
-
with gr.Group():
|
| 504 |
-
model_selection_header = gr.Markdown(f"### {i18n('model_selection')}")
|
| 505 |
-
with gr.Row():
|
| 506 |
-
auto_category_dropdown = gr.Dropdown(
|
| 507 |
-
label=i18n("model_category"),
|
| 508 |
-
choices=[i18n(cat) for cat in MODEL_CONFIGS.keys()],
|
| 509 |
-
value=i18n("Vocal Models")
|
| 510 |
-
)
|
| 511 |
-
selected_models = gr.Dropdown(
|
| 512 |
-
label=i18n("selected_models"),
|
| 513 |
-
choices=update_model_dropdown(i18n(initial_settings["auto_category"]), favorites=initial_favorites)["choices"],
|
| 514 |
-
value=initial_settings["selected_models"],
|
| 515 |
-
multiselect=True
|
| 516 |
-
)
|
| 517 |
-
|
| 518 |
-
preset_dropdown = gr.Dropdown(
|
| 519 |
-
label=i18n("select_preset"),
|
| 520 |
-
choices=list(initial_presets.keys()),
|
| 521 |
-
value=None,
|
| 522 |
-
allow_custom_value=False
|
| 523 |
-
)
|
| 524 |
-
with gr.Row():
|
| 525 |
-
preset_name_input = gr.Textbox(
|
| 526 |
-
label=i18n("preset_name"),
|
| 527 |
-
placeholder=i18n("enter_preset_name")
|
| 528 |
-
)
|
| 529 |
-
save_preset_btn = gr.Button(i18n("save_preset"), variant="secondary", scale=0)
|
| 530 |
-
delete_preset_btn = gr.Button(i18n("delete_preset"), variant="secondary", scale=0)
|
| 531 |
-
refresh_presets_btn = gr.Button(i18n("refresh_presets"), variant="secondary", scale=0)
|
| 532 |
-
|
| 533 |
-
with gr.Group():
|
| 534 |
-
ensemble_settings_header = gr.Markdown(f"### {i18n('ensemble_settings')}")
|
| 535 |
-
auto_ensemble_type = gr.Dropdown(
|
| 536 |
-
label=i18n("method"),
|
| 537 |
-
choices=['avg_wave', 'median_wave', 'min_wave', 'max_wave',
|
| 538 |
-
'avg_fft', 'median_fft', 'min_fft', 'max_fft'],
|
| 539 |
-
value=initial_settings["auto_ensemble_type"]
|
| 540 |
-
)
|
| 541 |
-
|
| 542 |
-
ensemble_recommendation = gr.Markdown(i18n("recommendation"))
|
| 543 |
-
|
| 544 |
-
auto_process_btn = gr.Button(i18n("start_processing"), variant="primary")
|
| 545 |
-
|
| 546 |
-
with gr.Column():
|
| 547 |
-
with gr.Tabs():
|
| 548 |
-
with gr.Tab(i18n("original_audio_tab")):
|
| 549 |
-
original_audio2 = gr.Audio(
|
| 550 |
-
label=i18n("original_audio"),
|
| 551 |
-
interactive=True,
|
| 552 |
-
elem_id="original_audio_player"
|
| 553 |
-
)
|
| 554 |
-
with gr.Tab(i18n("ensemble_result_tab")):
|
| 555 |
-
auto_output_audio = gr.Audio(
|
| 556 |
-
label=i18n("output_preview"),
|
| 557 |
-
show_download_button=True,
|
| 558 |
-
interactive=True
|
| 559 |
-
)
|
| 560 |
-
refresh_output_btn = gr.Button(i18n("refresh_output"), variant="secondary")
|
| 561 |
-
|
| 562 |
-
ensemble_progress_html = gr.HTML(
|
| 563 |
-
value=f"""
|
| 564 |
-
<div id="custom-progress">
|
| 565 |
-
<div id="progress-label">{i18n("waiting_for_processing")}</div>
|
| 566 |
-
<div style="width: 100%; background-color: #444; border-radius: 5px;">
|
| 567 |
-
<div id="progress-bar" style="width: 0%;"></div>
|
| 568 |
-
</div>
|
| 569 |
-
</div>
|
| 570 |
-
"""
|
| 571 |
-
)
|
| 572 |
-
ensemble_process_status = gr.Textbox(
|
| 573 |
-
label=i18n("status"),
|
| 574 |
-
interactive=False,
|
| 575 |
-
placeholder=i18n("waiting_for_processing"),
|
| 576 |
-
visible=False
|
| 577 |
-
)
|
| 578 |
-
|
| 579 |
-
with gr.Tab(i18n("download_sources_tab"), id="download_tab"):
|
| 580 |
-
with gr.Row():
|
| 581 |
-
with gr.Column():
|
| 582 |
-
gr.Markdown(f"### {i18n('direct_links')}")
|
| 583 |
-
direct_url_input = gr.Textbox(label=i18n("audio_file_url"))
|
| 584 |
-
direct_download_btn = gr.Button(i18n("download_from_url"), variant="secondary")
|
| 585 |
-
direct_download_status = gr.Textbox(label=i18n("download_status"))
|
| 586 |
-
direct_download_output = gr.File(label=i18n("downloaded_file"), interactive=False)
|
| 587 |
-
|
| 588 |
-
with gr.Column():
|
| 589 |
-
gr.Markdown(f"### {i18n('cookie_management')}")
|
| 590 |
-
cookie_file = gr.File(
|
| 591 |
-
label=i18n("upload_cookies_txt"),
|
| 592 |
-
file_types=[".txt"],
|
| 593 |
-
interactive=True,
|
| 594 |
-
elem_id="cookie_upload"
|
| 595 |
-
)
|
| 596 |
-
cookie_info = gr.Markdown(i18n("cookie_info"))
|
| 597 |
-
|
| 598 |
-
with gr.Tab(i18n("manual_ensemble_tab"), id="manual_ensemble_tab"):
|
| 599 |
-
with gr.Row(equal_height=True):
|
| 600 |
-
with gr.Column(scale=1, min_width=400):
|
| 601 |
-
with gr.Accordion(i18n("input_sources"), open=True):
|
| 602 |
-
with gr.Row():
|
| 603 |
-
refresh_btn = gr.Button(i18n("refresh"), variant="secondary", size="sm")
|
| 604 |
-
ensemble_type = gr.Dropdown(
|
| 605 |
-
label=i18n("ensemble_algorithm"),
|
| 606 |
-
choices=['avg_wave', 'median_wave', 'min_wave', 'max_wave',
|
| 607 |
-
'avg_fft', 'median_fft', 'min_fft', 'max_fft'],
|
| 608 |
-
value='avg_wave'
|
| 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 |
-
max_lines=20,
|
| 644 |
-
elem_id="log-box"
|
| 645 |
-
)
|
| 646 |
-
ensemble_process_btn = gr.Button(
|
| 647 |
-
i18n("process_ensemble"),
|
| 648 |
-
variant="primary",
|
| 649 |
-
size="sm",
|
| 650 |
-
elem_id="process-btn"
|
| 651 |
-
)
|
| 652 |
|
| 653 |
# Event handlers
|
| 654 |
-
def
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
return gr.update(value=i18n("remove_favorite") if is_favorited else i18n("add_favorite"))
|
| 659 |
-
|
| 660 |
-
def toggle_favorite(model, favorites_json):
|
| 661 |
-
favorites = json.loads(favorites_json)
|
| 662 |
-
if not model:
|
| 663 |
-
return json.dumps(favorites), gr.update(), gr.update()
|
| 664 |
-
cleaned_model = clean_model(model)
|
| 665 |
-
is_favorited = cleaned_model in favorites
|
| 666 |
-
new_favorites = update_favorites(favorites, cleaned_model, add=not is_favorited)
|
| 667 |
-
save_config(new_favorites, load_config()["settings"], load_config()["presets"])
|
| 668 |
-
category = model_category.value
|
| 669 |
-
return (
|
| 670 |
-
json.dumps(new_favorites),
|
| 671 |
-
gr.update(choices=update_model_dropdown(category, favorites=new_favorites)["choices"]),
|
| 672 |
-
gr.update(value=i18n("add_favorite") if is_favorited else i18n("remove_favorite"))
|
| 673 |
-
)
|
| 674 |
-
|
| 675 |
-
model_dropdown.change(
|
| 676 |
-
fn=update_favorite_button,
|
| 677 |
-
inputs=[model_dropdown, favorites_state],
|
| 678 |
-
outputs=favorite_button
|
| 679 |
-
)
|
| 680 |
-
|
| 681 |
-
favorite_button.click(
|
| 682 |
-
fn=toggle_favorite,
|
| 683 |
-
inputs=[model_dropdown, favorites_state],
|
| 684 |
-
outputs=[favorites_state, model_dropdown, favorite_button]
|
| 685 |
-
)
|
| 686 |
-
|
| 687 |
-
use_apollo.change(
|
| 688 |
-
fn=lambda x: gr.update(visible=x),
|
| 689 |
-
inputs=use_apollo,
|
| 690 |
-
outputs=apollo_settings_group
|
| 691 |
-
)
|
| 692 |
-
|
| 693 |
-
use_matchering.change(
|
| 694 |
-
fn=lambda x: gr.update(visible=x),
|
| 695 |
-
inputs=use_matchering,
|
| 696 |
-
outputs=matchering_settings_group
|
| 697 |
-
)
|
| 698 |
-
|
| 699 |
-
apollo_method.change(
|
| 700 |
-
fn=lambda x: [
|
| 701 |
-
gr.update(visible=x != i18n("mid_side_method")),
|
| 702 |
-
gr.update(visible=x == i18n("mid_side_method")),
|
| 703 |
-
"Apollo Universal Model" if x == i18n("mid_side_method") else None
|
| 704 |
-
],
|
| 705 |
-
inputs=apollo_method,
|
| 706 |
-
outputs=[apollo_normal_model_row, apollo_midside_model_row, apollo_normal_model]
|
| 707 |
-
)
|
| 708 |
-
|
| 709 |
-
def load_preset(preset_name, presets_json, category, favorites_json):
|
| 710 |
-
presets = json.loads(presets_json)
|
| 711 |
-
favorites = json.loads(favorites_json)
|
| 712 |
-
if preset_name and preset_name in presets:
|
| 713 |
-
preset = presets[preset_name]
|
| 714 |
-
favorite_models = [f"{model} ⭐" if model in favorites else model for model in preset["models"]]
|
| 715 |
-
preset_category = preset.get("auto_category_dropdown", category)
|
| 716 |
-
model_choices = update_model_dropdown(preset_category, favorites=favorites)["choices"]
|
| 717 |
-
logging.debug(f"Preset '{preset_name}' loaded with models: {favorite_models}, category: {preset_category}")
|
| 718 |
-
return (
|
| 719 |
-
gr.update(value=preset_category),
|
| 720 |
-
gr.update(choices=model_choices, value=favorite_models),
|
| 721 |
-
gr.update(value=preset["ensemble_method"])
|
| 722 |
-
)
|
| 723 |
-
logging.debug(f"Preset '{preset_name}' not found.")
|
| 724 |
-
return gr.update(), gr.update(), gr.update()
|
| 725 |
-
|
| 726 |
-
def sync_presets():
|
| 727 |
-
config = load_config()
|
| 728 |
-
return json.dumps(config["presets"]), gr.update(choices=list(config["presets"].keys()), value=None)
|
| 729 |
-
|
| 730 |
-
preset_dropdown.change(
|
| 731 |
-
fn=load_preset,
|
| 732 |
-
inputs=[preset_dropdown, presets_state, auto_category_dropdown, favorites_state],
|
| 733 |
-
outputs=[auto_category_dropdown, selected_models, auto_ensemble_type]
|
| 734 |
-
)
|
| 735 |
-
|
| 736 |
-
def handle_save_preset(preset_name, models, ensemble_method, presets_json, favorites_json, auto_category_dropdown):
|
| 737 |
-
presets = json.loads(presets_json)
|
| 738 |
-
favorites = json.loads(favorites_json)
|
| 739 |
-
if not preset_name:
|
| 740 |
-
return gr.update(), json.dumps(presets), i18n("no_preset_name_provided")
|
| 741 |
-
if not models and not favorites:
|
| 742 |
-
return gr.update(), json.dumps(presets), i18n("no_models_selected_for_preset")
|
| 743 |
-
new_presets = save_preset(
|
| 744 |
-
presets,
|
| 745 |
-
preset_name,
|
| 746 |
-
models,
|
| 747 |
-
ensemble_method,
|
| 748 |
-
auto_category_dropdown=auto_category_dropdown
|
| 749 |
-
)
|
| 750 |
-
save_config(favorites, load_config()["settings"], new_presets)
|
| 751 |
-
logging.debug(f"Preset dropdown updated with choices: {list(new_presets.keys())}")
|
| 752 |
-
return gr.update(choices=list(new_presets.keys()), value=None), json.dumps(new_presets), i18n("preset_saved").format(preset_name)
|
| 753 |
-
|
| 754 |
-
save_preset_btn.click(
|
| 755 |
-
fn=handle_save_preset,
|
| 756 |
-
inputs=[preset_name_input, selected_models, auto_ensemble_type, presets_state, favorites_state, auto_category_dropdown],
|
| 757 |
-
outputs=[preset_dropdown, presets_state]
|
| 758 |
-
)
|
| 759 |
-
|
| 760 |
-
def handle_delete_preset(preset_name, presets_json):
|
| 761 |
-
presets = json.loads(presets_json)
|
| 762 |
-
if not preset_name or preset_name not in presets:
|
| 763 |
-
return gr.update(), json.dumps(presets)
|
| 764 |
-
new_presets = delete_preset(presets, preset_name)
|
| 765 |
-
save_config(load_config()["favorites"], load_config()["settings"], new_presets)
|
| 766 |
-
return gr.update(choices=list(new_presets.keys()), value=None), json.dumps(new_presets)
|
| 767 |
-
|
| 768 |
-
delete_preset_btn.click(
|
| 769 |
-
fn=handle_delete_preset,
|
| 770 |
-
inputs=[preset_dropdown, presets_state],
|
| 771 |
-
outputs=[preset_dropdown, presets_state]
|
| 772 |
-
)
|
| 773 |
-
|
| 774 |
-
refresh_presets_btn.click(
|
| 775 |
-
fn=sync_presets,
|
| 776 |
-
inputs=[],
|
| 777 |
-
outputs=[presets_state, preset_dropdown]
|
| 778 |
-
)
|
| 779 |
-
|
| 780 |
-
auto_use_apollo.change(
|
| 781 |
-
fn=lambda x: gr.update(visible=x),
|
| 782 |
-
inputs=auto_use_apollo,
|
| 783 |
-
outputs=auto_apollo_settings_group
|
| 784 |
-
)
|
| 785 |
-
|
| 786 |
-
auto_use_matchering.change(
|
| 787 |
-
fn=lambda x: gr.update(visible=x),
|
| 788 |
-
inputs=auto_use_matchering,
|
| 789 |
-
outputs=auto_matchering_settings_group
|
| 790 |
-
)
|
| 791 |
-
|
| 792 |
-
auto_apollo_method.change(
|
| 793 |
-
fn=lambda x: [
|
| 794 |
-
gr.update(visible=x != i18n("mid_side_method")),
|
| 795 |
-
gr.update(visible=x == i18n("mid_side_method")),
|
| 796 |
-
"Apollo Universal Model" if x == i18n("mid_side_method") else None
|
| 797 |
-
],
|
| 798 |
-
inputs=auto_apollo_method,
|
| 799 |
-
outputs=[auto_apollo_normal_model_row, auto_apollo_midside_model_row, auto_apollo_normal_model]
|
| 800 |
-
)
|
| 801 |
-
|
| 802 |
-
def save_settings_on_process(*args):
|
| 803 |
-
apollo_method_value = args[11]
|
| 804 |
-
backend_apollo_method = "mid_side_method" if apollo_method_value == i18n("mid_side_method") else "normal_method"
|
| 805 |
-
cleaned_model = clean_model(args[1]) if args[1] else None
|
| 806 |
-
settings = {
|
| 807 |
-
"chunk_size": args[2],
|
| 808 |
-
"overlap": args[3],
|
| 809 |
-
"export_format": args[4],
|
| 810 |
-
"use_tta": args[5],
|
| 811 |
-
"use_demud_phaseremix_inst": args[6],
|
| 812 |
-
"extract_instrumental": args[7],
|
| 813 |
-
"use_apollo": args[8],
|
| 814 |
-
"apollo_chunk_size": args[9],
|
| 815 |
-
"apollo_overlap": args[10],
|
| 816 |
-
"apollo_method": backend_apollo_method,
|
| 817 |
-
"apollo_normal_model": args[12],
|
| 818 |
-
"apollo_midside_model": args[13],
|
| 819 |
-
"use_matchering": args[14],
|
| 820 |
-
"matchering_passes": args[15],
|
| 821 |
-
"model_category": args[16],
|
| 822 |
-
"selected_model": cleaned_model,
|
| 823 |
-
"auto_ensemble_type": args[7]
|
| 824 |
-
}
|
| 825 |
-
save_config(load_config()["favorites"], settings, load_config()["presets"])
|
| 826 |
-
modified_args = list(args)
|
| 827 |
-
modified_args[1] = cleaned_model
|
| 828 |
-
modified_args[17] = cleaned_model
|
| 829 |
-
return process_audio(*modified_args)
|
| 830 |
-
|
| 831 |
-
def save_auto_ensemble_settings(*args):
|
| 832 |
-
settings = load_config()["settings"]
|
| 833 |
-
settings["auto_ensemble_type"] = args[7]
|
| 834 |
-
settings["use_matchering"] = args[14]
|
| 835 |
-
settings["matchering_passes"] = args[15]
|
| 836 |
-
save_config(load_config()["favorites"], settings, load_config()["presets"])
|
| 837 |
-
output_audio, status, progress_html = None, i18n("waiting_for_processing"), ensemble_progress_html.value
|
| 838 |
-
for update in auto_ensemble_process(*args):
|
| 839 |
-
if isinstance(update, tuple) and len(update) == 3:
|
| 840 |
-
output_audio, status, progress_html = update
|
| 841 |
-
return output_audio, status, progress_html
|
| 842 |
-
|
| 843 |
-
def update_category_dropdowns(cat):
|
| 844 |
-
logging.debug(f"Input category: {cat}")
|
| 845 |
-
eng_cat = next((k for k in MODEL_CONFIGS.keys() if i18n(k) == cat), list(MODEL_CONFIGS.keys())[0])
|
| 846 |
-
logging.debug(f"Using English category: {eng_cat}")
|
| 847 |
-
choices = update_model_dropdown(eng_cat, favorites=load_config()["favorites"])["choices"]
|
| 848 |
-
logging.debug(f"Model choices: {choices}")
|
| 849 |
-
return gr.update(choices=choices), gr.update(choices=choices)
|
| 850 |
|
| 851 |
model_category.change(
|
| 852 |
-
fn=
|
| 853 |
inputs=model_category,
|
| 854 |
-
outputs=
|
| 855 |
)
|
| 856 |
|
| 857 |
-
clear_old_output_btn.click(fn=clear_old_output, outputs=clear_old_output_status)
|
| 858 |
-
|
| 859 |
input_audio_file.upload(
|
| 860 |
-
fn=lambda x
|
| 861 |
-
inputs=[input_audio_file
|
| 862 |
-
outputs=[input_audio_file, original_audio]
|
| 863 |
-
)
|
| 864 |
-
file_path_input.change(
|
| 865 |
-
fn=lambda x, y: handle_file_upload(x, y, is_auto_ensemble=False),
|
| 866 |
-
inputs=[input_audio_file, file_path_input],
|
| 867 |
outputs=[input_audio_file, original_audio]
|
| 868 |
)
|
| 869 |
|
| 870 |
-
auto_input_audio_file.upload(
|
| 871 |
-
fn=lambda x, y: handle_file_upload(x, y, is_auto_ensemble=True),
|
| 872 |
-
inputs=[auto_input_audio_file, auto_file_path_input],
|
| 873 |
-
outputs=[auto_input_audio_file, original_audio2]
|
| 874 |
-
)
|
| 875 |
-
auto_file_path_input.change(
|
| 876 |
-
fn=lambda x, y: handle_file_upload(x, y, is_auto_ensemble=True),
|
| 877 |
-
inputs=[auto_input_audio_file, auto_file_path_input],
|
| 878 |
-
outputs=[auto_input_audio_file, original_audio2]
|
| 879 |
-
)
|
| 880 |
-
|
| 881 |
-
auto_category_dropdown.change(
|
| 882 |
-
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"]),
|
| 883 |
-
inputs=auto_category_dropdown,
|
| 884 |
-
outputs=selected_models
|
| 885 |
-
)
|
| 886 |
-
|
| 887 |
-
def debug_inputs(*args):
|
| 888 |
-
input_names = [
|
| 889 |
-
"input_audio_file", "model_dropdown", "chunk_size", "overlap", "export_format",
|
| 890 |
-
"use_tta", "use_demud_phaseremix_inst", "extract_instrumental",
|
| 891 |
-
"use_apollo", "apollo_chunk_size", "apollo_overlap",
|
| 892 |
-
"apollo_method", "apollo_normal_model", "apollo_midside_model",
|
| 893 |
-
"use_matchering", "matchering_passes", "model_category", "selected_model"
|
| 894 |
-
]
|
| 895 |
-
cleaned_args = list(args)
|
| 896 |
-
cleaned_args[1] = clean_model(cleaned_args[1]) if cleaned_args[1] else None
|
| 897 |
-
cleaned_args[17] = clean_model(cleaned_args[17]) if cleaned_args[17] else None
|
| 898 |
-
for name, value in zip(input_names, cleaned_args):
|
| 899 |
-
logging.debug(f"UI Input - {name}: {value}")
|
| 900 |
-
return args
|
| 901 |
-
|
| 902 |
process_btn.click(
|
| 903 |
-
fn=
|
| 904 |
-
inputs=[
|
| 905 |
-
|
| 906 |
-
use_tta, use_demud_phaseremix_inst, extract_instrumental,
|
| 907 |
-
use_apollo, apollo_chunk_size, apollo_overlap,
|
| 908 |
-
apollo_method, apollo_normal_model, apollo_midside_model,
|
| 909 |
-
use_matchering, matchering_passes, model_category, model_dropdown
|
| 910 |
-
],
|
| 911 |
-
outputs=[
|
| 912 |
-
vocals_audio, instrumental_audio, phaseremix_audio, drum_audio, karaoke_audio,
|
| 913 |
-
other_audio, bass_audio, effects_audio, speech_audio, bleed_audio, music_audio,
|
| 914 |
-
dry_audio, male_audio, female_audio,
|
| 915 |
-
separation_process_status, separation_progress_html
|
| 916 |
-
]
|
| 917 |
)
|
| 918 |
|
| 919 |
-
|
| 920 |
-
fn=
|
| 921 |
-
|
| 922 |
-
auto_input_audio_file,
|
| 923 |
-
selected_models,
|
| 924 |
-
auto_chunk_size,
|
| 925 |
-
auto_overlap,
|
| 926 |
-
export_format2,
|
| 927 |
-
auto_use_tta,
|
| 928 |
-
auto_extract_instrumental,
|
| 929 |
-
auto_ensemble_type,
|
| 930 |
-
gr.State(None),
|
| 931 |
-
auto_use_apollo,
|
| 932 |
-
auto_apollo_normal_model,
|
| 933 |
-
auto_apollo_chunk_size,
|
| 934 |
-
auto_apollo_overlap,
|
| 935 |
-
auto_apollo_method,
|
| 936 |
-
auto_use_matchering,
|
| 937 |
-
auto_matchering_passes,
|
| 938 |
-
auto_apollo_midside_model
|
| 939 |
-
],
|
| 940 |
-
outputs=[auto_output_audio, ensemble_process_status, ensemble_progress_html]
|
| 941 |
)
|
| 942 |
|
| 943 |
-
direct_download_btn.click(
|
| 944 |
-
fn=download_callback,
|
| 945 |
-
inputs=[direct_url_input, gr.State('direct'), cookie_file],
|
| 946 |
-
outputs=[direct_download_output, direct_download_status, input_audio_file, auto_input_audio_file, original_audio, original_audio2]
|
| 947 |
-
)
|
| 948 |
-
|
| 949 |
-
refresh_output_btn.click(
|
| 950 |
-
fn=refresh_auto_output,
|
| 951 |
-
inputs=[],
|
| 952 |
-
outputs=[auto_output_audio, ensemble_process_status]
|
| 953 |
-
)
|
| 954 |
-
|
| 955 |
-
refresh_btn.click(fn=update_file_list, outputs=file_dropdown)
|
| 956 |
-
ensemble_process_btn.click(fn=ensemble_audio_fn, inputs=[file_dropdown, ensemble_type, weights_input], outputs=[ensemble_output_audio, ensemble_status])
|
| 957 |
-
|
| 958 |
return demo
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import logging
|
| 5 |
+
from helpers import update_model_dropdown, handle_file_upload, clear_old_output
|
| 6 |
+
from model import MODEL_CONFIGS
|
| 7 |
+
from processing import process_audio
|
| 8 |
+
from assets.i18n.i18n import I18nAuto
|
| 9 |
+
from config_manager import load_config
|
| 10 |
|
| 11 |
logging.basicConfig(filename='sesa_gui.log', level=logging.DEBUG)
|
| 12 |
|
| 13 |
+
# BASE_DIR and config setup
|
| 14 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 15 |
CONFIG_DIR = os.path.join(BASE_DIR, "assets")
|
| 16 |
CONFIG_FILE = os.path.join(CONFIG_DIR, "config.json")
|
|
|
|
| 17 |
|
| 18 |
+
# Load user config
|
| 19 |
user_config = load_config()
|
| 20 |
initial_settings = user_config["settings"]
|
| 21 |
initial_favorites = user_config["favorites"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Initialize I18nAuto
|
| 24 |
i18n = I18nAuto()
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def create_interface():
|
| 27 |
css = """
|
| 28 |
+
body { background: #222; color: #fff; font-family: Arial, sans-serif; }
|
| 29 |
+
.gr-tab { background: #444 !important; color: #fff !important; border: 1px solid #888 !important; }
|
| 30 |
+
button { background: #555 !important; color: #fff !important; border: 1px solid #888 !important; }
|
| 31 |
+
button:hover { background: #777 !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
"""
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 35 |
+
# Store state in hidden Textbox
|
|
|
|
| 36 |
favorites_state = gr.Textbox(value=json.dumps(initial_favorites), visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
gr.HTML(f"<h1>{i18n('SESA Audio Separation')}</h1>")
|
| 39 |
+
|
| 40 |
+
with gr.Tab(i18n("audio_separation_tab")):
|
| 41 |
+
with gr.Row():
|
| 42 |
+
with gr.Column():
|
| 43 |
+
input_audio_file = gr.File(
|
| 44 |
+
file_types=[".wav", ".mp3", ".flac"],
|
| 45 |
+
label=i18n("upload_file")
|
| 46 |
+
)
|
| 47 |
+
model_category = gr.Dropdown(
|
| 48 |
+
label=i18n("category"),
|
| 49 |
+
choices=[i18n(cat) for cat in MODEL_CONFIGS.keys()],
|
| 50 |
+
value=i18n(initial_settings["model_category"])
|
| 51 |
+
)
|
| 52 |
+
model_dropdown = gr.Dropdown(
|
| 53 |
+
label=i18n("model"),
|
| 54 |
+
choices=update_model_dropdown(i18n(initial_settings["model_category"]), favorites=initial_favorites)["choices"],
|
| 55 |
+
value=initial_settings["selected_model"]
|
| 56 |
+
)
|
| 57 |
+
export_format = gr.Dropdown(
|
| 58 |
+
label=i18n("format"),
|
| 59 |
+
choices=['wav FLOAT', 'flac PCM_16'],
|
| 60 |
+
value=initial_settings["export_format"]
|
| 61 |
+
)
|
| 62 |
+
process_btn = gr.Button(i18n("process"))
|
| 63 |
+
clear_old_output_btn = gr.Button(i18n("reset"))
|
| 64 |
+
|
| 65 |
+
with gr.Column():
|
| 66 |
+
original_audio = gr.Audio(label=i18n("original"))
|
| 67 |
+
vocals_audio = gr.Audio(label=i18n("vocals"))
|
| 68 |
+
instrumental_audio = gr.Audio(label=i18n("instrumental_output"))
|
| 69 |
+
status = gr.Textbox(label=i18n("status"), interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
# Event handlers
|
| 72 |
+
def update_models(category):
|
| 73 |
+
logging.debug(f"Updating models for category: {category}")
|
| 74 |
+
choices = update_model_dropdown(category, favorites=json.loads(favorites_state.value))["choices"]
|
| 75 |
+
return gr.update(choices=choices)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
model_category.change(
|
| 78 |
+
fn=update_models,
|
| 79 |
inputs=model_category,
|
| 80 |
+
outputs=model_dropdown
|
| 81 |
)
|
| 82 |
|
|
|
|
|
|
|
| 83 |
input_audio_file.upload(
|
| 84 |
+
fn=lambda x: handle_file_upload(x, None, is_auto_ensemble=False),
|
| 85 |
+
inputs=[input_audio_file],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
outputs=[input_audio_file, original_audio]
|
| 87 |
)
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
process_btn.click(
|
| 90 |
+
fn=process_audio,
|
| 91 |
+
inputs=[input_audio_file, model_dropdown, export_format],
|
| 92 |
+
outputs=[vocals_audio, instrumental_audio, status]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
)
|
| 94 |
|
| 95 |
+
clear_old_output_btn.click(
|
| 96 |
+
fn=clear_old_output,
|
| 97 |
+
outputs=status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
)
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
return demo
|