Update gui.py
Browse files
gui.py
CHANGED
|
@@ -15,9 +15,10 @@ from processing import process_audio, auto_ensemble_process, ensemble_audio_fn,
|
|
| 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 |
logging.basicConfig(filename='sesa_gui.log', level=logging.DEBUG)
|
| 19 |
|
| 20 |
-
# BASE_DIR
|
| 21 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
CONFIG_DIR = os.path.join(BASE_DIR, "assets")
|
| 23 |
CONFIG_FILE = os.path.join(CONFIG_DIR, "config.json")
|
|
@@ -33,56 +34,54 @@ initial_presets = user_config["presets"]
|
|
| 33 |
if "auto_category" not in initial_settings or initial_settings["auto_category"] not in MODEL_CONFIGS:
|
| 34 |
initial_settings["auto_category"] = "Vocal Models"
|
| 35 |
|
| 36 |
-
#
|
| 37 |
if not os.path.exists(CONFIG_FILE):
|
| 38 |
default_config = {
|
| 39 |
"lang": {"override": False, "selected_lang": "auto"},
|
| 40 |
"sharing": {
|
| 41 |
"method": "gradio",
|
| 42 |
"ngrok_token": "",
|
| 43 |
-
"port": random.randint(1000, 9000)
|
| 44 |
}
|
| 45 |
}
|
| 46 |
os.makedirs(CONFIG_DIR, exist_ok=True)
|
| 47 |
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
| 48 |
json.dump(default_config, f, indent=2)
|
| 49 |
-
else:
|
| 50 |
try:
|
| 51 |
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
|
| 52 |
config = json.load(f)
|
| 53 |
-
# Ensure 'lang' key exists
|
| 54 |
if "lang" not in config:
|
| 55 |
config["lang"] = {"override": False, "selected_lang": "auto"}
|
| 56 |
-
# Add 'sharing' key if it doesn't exist
|
| 57 |
if "sharing" not in config:
|
| 58 |
config["sharing"] = {
|
| 59 |
"method": "gradio",
|
| 60 |
"ngrok_token": "",
|
| 61 |
-
"port": random.randint(1000, 9000)
|
| 62 |
}
|
| 63 |
-
|
| 64 |
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
| 65 |
json.dump(config, f, indent=2)
|
| 66 |
-
except json.JSONDecodeError:
|
| 67 |
print("Warning: config.json is corrupted. Creating a new one.")
|
| 68 |
default_config = {
|
| 69 |
"lang": {"override": False, "selected_lang": "auto"},
|
| 70 |
"sharing": {
|
| 71 |
"method": "gradio",
|
| 72 |
"ngrok_token": "",
|
| 73 |
-
"port": random.randint(1000, 9000)
|
| 74 |
}
|
| 75 |
}
|
| 76 |
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
| 77 |
json.dump(default_config, f, indent=2)
|
| 78 |
|
| 79 |
-
# I18nAuto
|
| 80 |
i18n = I18nAuto()
|
| 81 |
|
| 82 |
-
#
|
| 83 |
OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
|
| 84 |
|
| 85 |
-
#
|
| 86 |
def create_interface():
|
| 87 |
css = """
|
| 88 |
body {
|
|
@@ -198,16 +197,18 @@ def create_interface():
|
|
| 198 |
}
|
| 199 |
"""
|
| 200 |
|
| 201 |
-
# Load user config
|
| 202 |
user_config = load_config()
|
| 203 |
initial_settings = user_config["settings"]
|
| 204 |
initial_favorites = user_config["favorites"]
|
| 205 |
initial_presets = user_config["presets"]
|
| 206 |
|
| 207 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
| 211 |
|
| 212 |
header_html = gr.HTML(
|
| 213 |
value=f"""
|
|
@@ -220,16 +221,16 @@ def create_interface():
|
|
| 220 |
with gr.Tab(i18n("audio_separation_tab"), id="separation_tab"):
|
| 221 |
with gr.Row(equal_height=True):
|
| 222 |
with gr.Column(scale=1, min_width=380):
|
| 223 |
-
with gr.Accordion(i18n("input_model"), open=True)
|
| 224 |
with gr.Tabs():
|
| 225 |
-
with gr.Tab(i18n("upload"))
|
| 226 |
input_audio_file = gr.File(
|
| 227 |
file_types=[".wav", ".mp3", ".m4a", ".mp4", ".mkv", ".flac"],
|
| 228 |
-
elem_classes=["compact-upload", "horizontal"
|
| 229 |
-
label=""
|
| 230 |
)
|
| 231 |
-
with gr.Tab(i18n("path"))
|
| 232 |
-
file_path_input = gr.Textbox(placeholder=i18n("path_placeholder"))
|
| 233 |
|
| 234 |
with gr.Row():
|
| 235 |
model_category = gr.Dropdown(
|
|
@@ -245,225 +246,151 @@ def create_interface():
|
|
| 245 |
value=initial_settings["selected_model"]
|
| 246 |
)
|
| 247 |
|
| 248 |
-
with gr.Accordion(i18n("settings"), open=False)
|
| 249 |
with gr.Row():
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
info=i18n("chunk_size_info")
|
| 262 |
-
)
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
info=i18n("overlap_info")
|
| 273 |
-
)
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
value=initial_settings["use_tta"]
|
| 281 |
-
)
|
| 282 |
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
value=initial_settings["use_demud_phaseremix_inst"]
|
| 289 |
-
)
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
)
|
| 297 |
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
)
|
| 304 |
|
| 305 |
with gr.Group(visible=initial_settings["use_apollo"]) as apollo_settings_group:
|
| 306 |
with gr.Row():
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
info=i18n("apollo_chunk_size_info"),
|
| 315 |
-
interactive=True
|
| 316 |
-
)
|
| 317 |
-
with gr.Column(scale=1):
|
| 318 |
-
apollo_overlap = gr.Slider(
|
| 319 |
-
label=i18n("apollo_overlap"),
|
| 320 |
-
minimum=2,
|
| 321 |
-
maximum=10,
|
| 322 |
-
step=1,
|
| 323 |
-
value=initial_settings["apollo_overlap"],
|
| 324 |
-
info=i18n("apollo_overlap_info"),
|
| 325 |
-
interactive=True
|
| 326 |
-
)
|
| 327 |
-
|
| 328 |
-
with gr.Row():
|
| 329 |
-
apollo_method = gr.Dropdown(
|
| 330 |
-
label=i18n("apollo_processing_method"),
|
| 331 |
-
choices=[i18n("normal_method"), i18n("mid_side_method")],
|
| 332 |
-
value=i18n(initial_settings["apollo_method"]),
|
| 333 |
-
interactive=True
|
| 334 |
)
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
value=initial_settings["
|
| 341 |
-
|
| 342 |
)
|
| 343 |
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
interactive=True
|
| 350 |
-
)
|
| 351 |
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
label=i18n("
|
| 355 |
-
|
| 356 |
-
|
|
|
|
| 357 |
)
|
| 358 |
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
label=i18n("
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
value=initial_settings.get("matchering_passes", 1),
|
| 366 |
-
info=i18n("matchering_passes_info"),
|
| 367 |
-
interactive=True
|
| 368 |
)
|
| 369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
with gr.Row():
|
| 371 |
process_btn = gr.Button(i18n("process"), variant="primary")
|
| 372 |
clear_old_output_btn = gr.Button(i18n("reset"), variant="secondary")
|
| 373 |
clear_old_output_status = gr.Textbox(label=i18n("status"), interactive=False)
|
| 374 |
|
| 375 |
-
# Favorite handler
|
| 376 |
-
def update_favorite_button(model, favorites):
|
| 377 |
-
cleaned_model = clean_model(model) if model else None
|
| 378 |
-
is_favorited = cleaned_model in favorites if cleaned_model else False
|
| 379 |
-
return gr.update(value=i18n("remove_favorite") if is_favorited else i18n("add_favorite"))
|
| 380 |
-
|
| 381 |
-
def toggle_favorite(model, favorites):
|
| 382 |
-
if not model:
|
| 383 |
-
return favorites, gr.update(), gr.update()
|
| 384 |
-
cleaned_model = clean_model(model)
|
| 385 |
-
is_favorited = cleaned_model in favorites
|
| 386 |
-
new_favorites = update_favorites(favorites, cleaned_model, add=not is_favorited)
|
| 387 |
-
save_config(new_favorites, load_config()["settings"], load_config()["presets"])
|
| 388 |
-
category = model_category.value
|
| 389 |
-
return (
|
| 390 |
-
new_favorites,
|
| 391 |
-
gr.update(choices=update_model_dropdown(category, favorites=new_favorites)["choices"]),
|
| 392 |
-
gr.update(value=i18n("add_favorite") if is_favorited else i18n("remove_favorite"))
|
| 393 |
-
)
|
| 394 |
-
|
| 395 |
-
model_dropdown.change(
|
| 396 |
-
fn=update_favorite_button,
|
| 397 |
-
inputs=[model_dropdown, favorites_state],
|
| 398 |
-
outputs=favorite_button
|
| 399 |
-
)
|
| 400 |
-
|
| 401 |
-
favorite_button.click(
|
| 402 |
-
fn=toggle_favorite,
|
| 403 |
-
inputs=[model_dropdown, favorites_state],
|
| 404 |
-
outputs=[favorites_state, model_dropdown, favorite_button]
|
| 405 |
-
)
|
| 406 |
-
|
| 407 |
-
use_apollo.change(
|
| 408 |
-
fn=lambda x: gr.update(visible=x),
|
| 409 |
-
inputs=use_apollo,
|
| 410 |
-
outputs=apollo_settings_group
|
| 411 |
-
)
|
| 412 |
-
|
| 413 |
-
use_matchering.change(
|
| 414 |
-
fn=lambda x: gr.update(visible=x),
|
| 415 |
-
inputs=use_matchering,
|
| 416 |
-
outputs=matchering_settings_group
|
| 417 |
-
)
|
| 418 |
-
|
| 419 |
-
apollo_method.change(
|
| 420 |
-
fn=lambda x: [
|
| 421 |
-
gr.update(visible=x != i18n("mid_side_method")),
|
| 422 |
-
gr.update(visible=x == i18n("mid_side_method")),
|
| 423 |
-
"Apollo Universal Model" if x == i18n("mid_side_method") else None
|
| 424 |
-
],
|
| 425 |
-
inputs=apollo_method,
|
| 426 |
-
outputs=[apollo_normal_model_row, apollo_midside_model_row, apollo_normal_model]
|
| 427 |
-
)
|
| 428 |
-
|
| 429 |
with gr.Column(scale=2, min_width=800):
|
| 430 |
with gr.Tabs():
|
| 431 |
-
with gr.Tab(i18n("main_tab"))
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
music_audio = gr.Audio(label=i18n("music"))
|
| 458 |
-
karaoke_audio = gr.Audio(label=i18n("karaoke"))
|
| 459 |
-
bleed_audio = gr.Audio(label=i18n("bleed"))
|
| 460 |
|
| 461 |
separation_progress_html = gr.HTML(
|
| 462 |
value=f"""
|
| 463 |
-
<div id="custom-progress"
|
| 464 |
-
<div
|
| 465 |
-
<div style="width: 100%; background-color: #444; border-radius: 5px;
|
| 466 |
-
<div id="progress-bar" style="width: 0%;
|
| 467 |
</div>
|
| 468 |
</div>
|
| 469 |
"""
|
|
@@ -486,11 +413,10 @@ def create_interface():
|
|
| 486 |
)
|
| 487 |
auto_file_path_input = gr.Textbox(
|
| 488 |
label=i18n("enter_file_path"),
|
| 489 |
-
placeholder=i18n("file_path_placeholder")
|
| 490 |
-
interactive=True
|
| 491 |
)
|
| 492 |
|
| 493 |
-
with gr.Accordion(i18n("advanced_settings"), open=False)
|
| 494 |
with gr.Row():
|
| 495 |
auto_use_tta = gr.Checkbox(label=i18n("use_tta"), value=False)
|
| 496 |
auto_extract_instrumental = gr.Checkbox(label=i18n("instrumental_only"))
|
|
@@ -514,76 +440,67 @@ def create_interface():
|
|
| 514 |
value='wav FLOAT'
|
| 515 |
)
|
| 516 |
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
)
|
| 523 |
|
| 524 |
with gr.Group(visible=False) as auto_apollo_settings_group:
|
| 525 |
with gr.Row():
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
info=i18n("apollo_chunk_size_info"),
|
| 534 |
-
interactive=True
|
| 535 |
-
)
|
| 536 |
-
with gr.Column(scale=1):
|
| 537 |
-
auto_apollo_overlap = gr.Slider(
|
| 538 |
-
label=i18n("apollo_overlap"),
|
| 539 |
-
minimum=2,
|
| 540 |
-
maximum=10,
|
| 541 |
-
step=1,
|
| 542 |
-
value=2,
|
| 543 |
-
info=i18n("apollo_overlap_info"),
|
| 544 |
-
interactive=True
|
| 545 |
-
)
|
| 546 |
-
|
| 547 |
-
with gr.Row():
|
| 548 |
-
auto_apollo_method = gr.Dropdown(
|
| 549 |
-
label=i18n("apollo_processing_method"),
|
| 550 |
-
choices=[i18n("normal_method"), i18n("mid_side_method")],
|
| 551 |
-
value=i18n("normal_method"),
|
| 552 |
-
interactive=True
|
| 553 |
)
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
value=
|
| 560 |
-
|
| 561 |
)
|
| 562 |
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
interactive=True
|
| 569 |
-
)
|
| 570 |
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
label=i18n("
|
| 574 |
-
|
| 575 |
-
|
|
|
|
| 576 |
)
|
| 577 |
|
| 578 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
auto_matchering_passes = gr.Slider(
|
| 580 |
label=i18n("matchering_passes"),
|
| 581 |
minimum=1,
|
| 582 |
maximum=5,
|
| 583 |
step=1,
|
| 584 |
value=1,
|
| 585 |
-
info=i18n("matchering_passes_info")
|
| 586 |
-
interactive=True
|
| 587 |
)
|
| 588 |
|
| 589 |
with gr.Group():
|
|
@@ -601,19 +518,16 @@ def create_interface():
|
|
| 601 |
multiselect=True
|
| 602 |
)
|
| 603 |
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
interactive=True
|
| 611 |
-
)
|
| 612 |
with gr.Row():
|
| 613 |
preset_name_input = gr.Textbox(
|
| 614 |
label=i18n("preset_name"),
|
| 615 |
-
placeholder=i18n("enter_preset_name")
|
| 616 |
-
interactive=True
|
| 617 |
)
|
| 618 |
save_preset_btn = gr.Button(i18n("save_preset"), variant="secondary", scale=0)
|
| 619 |
delete_preset_btn = gr.Button(i18n("delete_preset"), variant="secondary", scale=0)
|
|
@@ -621,133 +535,39 @@ def create_interface():
|
|
| 621 |
|
| 622 |
with gr.Group():
|
| 623 |
ensemble_settings_header = gr.Markdown(f"### {i18n('ensemble_settings')}")
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
)
|
| 631 |
|
| 632 |
ensemble_recommendation = gr.Markdown(i18n("recommendation"))
|
| 633 |
|
| 634 |
auto_process_btn = gr.Button(i18n("start_processing"), variant="primary")
|
| 635 |
|
| 636 |
-
def load_preset(preset_name, presets, category, favorites):
|
| 637 |
-
if preset_name and preset_name in presets:
|
| 638 |
-
preset = presets[preset_name]
|
| 639 |
-
# Mark starred models with ⭐
|
| 640 |
-
favorite_models = [f"{model} ⭐" if model in favorites else model for model in preset["models"]]
|
| 641 |
-
# Get the category from the preset, default to current category if not specified
|
| 642 |
-
preset_category = preset.get("auto_category_dropdown", category)
|
| 643 |
-
# Update model choices based on the preset's category
|
| 644 |
-
model_choices = update_model_dropdown(preset_category, favorites=favorites)["choices"]
|
| 645 |
-
print(f"Preset '{preset_name}' loaded with models: {favorite_models}, category: {preset_category}")
|
| 646 |
-
return (
|
| 647 |
-
gr.update(value=preset_category), # Update auto_category_dropdown
|
| 648 |
-
gr.update(choices=model_choices, value=favorite_models), # Update selected_models
|
| 649 |
-
gr.update(value=preset["ensemble_method"]) # Update auto_ensemble_type
|
| 650 |
-
)
|
| 651 |
-
print(f"Preset '{preset_name}' not found.")
|
| 652 |
-
return gr.update(), gr.update(), gr.update()
|
| 653 |
-
|
| 654 |
-
def sync_presets():
|
| 655 |
-
"""Reload presets from config and update dropdown."""
|
| 656 |
-
config = load_config()
|
| 657 |
-
return config["presets"], gr.update(choices=list(config["presets"].keys()), value=None)
|
| 658 |
-
|
| 659 |
-
preset_dropdown.change(
|
| 660 |
-
fn=load_preset,
|
| 661 |
-
inputs=[preset_dropdown, presets_state, auto_category_dropdown, favorites_state],
|
| 662 |
-
outputs=[auto_category_dropdown, selected_models, auto_ensemble_type]
|
| 663 |
-
)
|
| 664 |
-
|
| 665 |
-
def handle_save_preset(preset_name, models, ensemble_method, presets, favorites, auto_category_dropdown):
|
| 666 |
-
if not preset_name:
|
| 667 |
-
return gr.update(), presets, i18n("no_preset_name_provided")
|
| 668 |
-
if not models and not favorites:
|
| 669 |
-
return gr.update(), presets, i18n("no_models_selected_for_preset")
|
| 670 |
-
new_presets = save_preset(
|
| 671 |
-
presets,
|
| 672 |
-
preset_name,
|
| 673 |
-
models,
|
| 674 |
-
ensemble_method,
|
| 675 |
-
auto_category_dropdown=auto_category_dropdown # Pass the category explicitly
|
| 676 |
-
)
|
| 677 |
-
save_config(favorites, load_config()["settings"], new_presets)
|
| 678 |
-
print(f"Preset dropdown updated with choices: {list(new_presets.keys())}")
|
| 679 |
-
return gr.update(choices=list(new_presets.keys()), value=None), new_presets, i18n("preset_saved").format(preset_name)
|
| 680 |
-
|
| 681 |
-
save_preset_btn.click(
|
| 682 |
-
fn=handle_save_preset,
|
| 683 |
-
inputs=[preset_name_input, selected_models, auto_ensemble_type, presets_state, favorites_state, auto_category_dropdown],
|
| 684 |
-
outputs=[preset_dropdown, presets_state]
|
| 685 |
-
)
|
| 686 |
-
|
| 687 |
-
def handle_delete_preset(preset_name, presets):
|
| 688 |
-
if not preset_name or preset_name not in presets:
|
| 689 |
-
return gr.update(), presets
|
| 690 |
-
new_presets = delete_preset(presets, preset_name)
|
| 691 |
-
save_config(load_config()["favorites"], load_config()["settings"], new_presets)
|
| 692 |
-
return gr.update(choices=list(new_presets.keys()), value=None), new_presets
|
| 693 |
-
|
| 694 |
-
delete_preset_btn.click(
|
| 695 |
-
fn=handle_delete_preset,
|
| 696 |
-
inputs=[preset_dropdown, presets_state],
|
| 697 |
-
outputs=[preset_dropdown, presets_state]
|
| 698 |
-
)
|
| 699 |
-
|
| 700 |
-
refresh_presets_btn.click(
|
| 701 |
-
fn=sync_presets,
|
| 702 |
-
inputs=[],
|
| 703 |
-
outputs=[presets_state, preset_dropdown]
|
| 704 |
-
)
|
| 705 |
-
|
| 706 |
-
auto_use_apollo.change(
|
| 707 |
-
fn=lambda x: gr.update(visible=x),
|
| 708 |
-
inputs=auto_use_apollo,
|
| 709 |
-
outputs=auto_apollo_settings_group
|
| 710 |
-
)
|
| 711 |
-
|
| 712 |
-
auto_use_matchering.change(
|
| 713 |
-
fn=lambda x: gr.update(visible=x),
|
| 714 |
-
inputs=auto_use_matchering,
|
| 715 |
-
outputs=auto_matchering_settings_group
|
| 716 |
-
)
|
| 717 |
-
|
| 718 |
-
auto_apollo_method.change(
|
| 719 |
-
fn=lambda x: [
|
| 720 |
-
gr.update(visible=x != i18n("mid_side_method")),
|
| 721 |
-
gr.update(visible=x == i18n("mid_side_method")),
|
| 722 |
-
"Apollo Universal Model" if x == i18n("mid_side_method") else None
|
| 723 |
-
],
|
| 724 |
-
inputs=auto_apollo_method,
|
| 725 |
-
outputs=[auto_apollo_normal_model_row, auto_apollo_midside_model_row, auto_apollo_normal_model]
|
| 726 |
-
)
|
| 727 |
-
|
| 728 |
with gr.Column():
|
| 729 |
with gr.Tabs():
|
| 730 |
-
with gr.Tab(i18n("original_audio_tab"))
|
| 731 |
original_audio2 = gr.Audio(
|
| 732 |
label=i18n("original_audio"),
|
| 733 |
-
interactive=
|
| 734 |
-
every=1,
|
| 735 |
elem_id="original_audio_player"
|
| 736 |
)
|
| 737 |
-
with gr.Tab(i18n("ensemble_result_tab"))
|
| 738 |
auto_output_audio = gr.Audio(
|
| 739 |
label=i18n("output_preview"),
|
| 740 |
show_download_button=True,
|
| 741 |
-
interactive=
|
| 742 |
)
|
| 743 |
refresh_output_btn = gr.Button(i18n("refresh_output"), variant="secondary")
|
| 744 |
|
| 745 |
ensemble_progress_html = gr.HTML(
|
| 746 |
value=f"""
|
| 747 |
-
<div id="custom-progress"
|
| 748 |
-
<div
|
| 749 |
-
<div style="width: 100%; background-color: #444; border-radius: 5px;
|
| 750 |
-
<div id="progress-bar" style="width: 0%;
|
| 751 |
</div>
|
| 752 |
</div>
|
| 753 |
"""
|
|
@@ -758,7 +578,7 @@ def create_interface():
|
|
| 758 |
placeholder=i18n("waiting_for_processing"),
|
| 759 |
visible=False
|
| 760 |
)
|
| 761 |
-
|
| 762 |
with gr.Tab(i18n("download_sources_tab"), id="download_tab"):
|
| 763 |
with gr.Row():
|
| 764 |
with gr.Column():
|
|
@@ -781,7 +601,7 @@ def create_interface():
|
|
| 781 |
with gr.Tab(i18n("manual_ensemble_tab"), id="manual_ensemble_tab"):
|
| 782 |
with gr.Row(equal_height=True):
|
| 783 |
with gr.Column(scale=1, min_width=400):
|
| 784 |
-
with gr.Accordion(i18n("input_sources"), open=True)
|
| 785 |
with gr.Row():
|
| 786 |
refresh_btn = gr.Button(i18n("refresh"), variant="secondary", size="sm")
|
| 787 |
ensemble_type = gr.Dropdown(
|
|
@@ -809,14 +629,14 @@ def create_interface():
|
|
| 809 |
|
| 810 |
with gr.Column(scale=2, min_width=800):
|
| 811 |
with gr.Tabs():
|
| 812 |
-
with gr.Tab(i18n("result_preview_tab"))
|
| 813 |
ensemble_output_audio = gr.Audio(
|
| 814 |
label=i18n("ensembled_output"),
|
| 815 |
-
interactive=
|
| 816 |
show_download_button=True,
|
| 817 |
elem_id="output-audio"
|
| 818 |
)
|
| 819 |
-
with gr.Tab(i18n("processing_log_tab"))
|
| 820 |
with gr.Accordion(i18n("processing_details"), open=True, elem_id="log-accordion"):
|
| 821 |
ensemble_status = gr.Textbox(
|
| 822 |
label="",
|
|
@@ -826,13 +646,161 @@ def create_interface():
|
|
| 826 |
max_lines=20,
|
| 827 |
elem_id="log-box"
|
| 828 |
)
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 836 |
|
| 837 |
def save_settings_on_process(*args):
|
| 838 |
apollo_method_value = args[11]
|
|
@@ -865,11 +833,10 @@ def create_interface():
|
|
| 865 |
|
| 866 |
def save_auto_ensemble_settings(*args):
|
| 867 |
settings = load_config()["settings"]
|
| 868 |
-
settings["
|
| 869 |
settings["use_matchering"] = args[14]
|
| 870 |
settings["matchering_passes"] = args[15]
|
| 871 |
save_config(load_config()["favorites"], settings, load_config()["presets"])
|
| 872 |
-
# Handle generator output from auto_ensemble_process
|
| 873 |
output_audio, status, progress_html = None, i18n("waiting_for_processing"), ensemble_progress_html.value
|
| 874 |
for update in auto_ensemble_process(*args):
|
| 875 |
if isinstance(update, tuple) and len(update) == 3:
|
|
@@ -932,7 +899,7 @@ def create_interface():
|
|
| 932 |
cleaned_args[1] = clean_model(cleaned_args[1]) if cleaned_args[1] else None
|
| 933 |
cleaned_args[17] = clean_model(cleaned_args[17]) if cleaned_args[17] else None
|
| 934 |
for name, value in zip(input_names, cleaned_args):
|
| 935 |
-
|
| 936 |
return args
|
| 937 |
|
| 938 |
process_btn.click(
|
|
@@ -991,4 +958,4 @@ def create_interface():
|
|
| 991 |
refresh_btn.click(fn=update_file_list, outputs=file_dropdown)
|
| 992 |
ensemble_process_btn.click(fn=ensemble_audio_fn, inputs=[file_dropdown, ensemble_type, weights_input], outputs=[ensemble_output_audio, ensemble_status])
|
| 993 |
|
| 994 |
-
return demo
|
|
|
|
| 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 definition
|
| 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")
|
|
|
|
| 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 off
|
| 63 |
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
| 64 |
json.dump(config, f, indent=2)
|
| 65 |
+
except json.JSONDecodeError:
|
| 66 |
print("Warning: config.json is corrupted. Creating a new one.")
|
| 67 |
default_config = {
|
| 68 |
"lang": {"override": False, "selected_lang": "auto"},
|
| 69 |
"sharing": {
|
| 70 |
"method": "gradio",
|
| 71 |
"ngrok_token": "",
|
| 72 |
+
"port": random.randint(1000, 9000)
|
| 73 |
}
|
| 74 |
}
|
| 75 |
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
| 76 |
json.dump(default_config, f, indent=2)
|
| 77 |
|
| 78 |
+
# Initialize I18nAuto
|
| 79 |
i18n = I18nAuto()
|
| 80 |
|
| 81 |
+
# Output formats
|
| 82 |
OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
|
| 83 |
|
| 84 |
+
# Interface creation function
|
| 85 |
def create_interface():
|
| 86 |
css = """
|
| 87 |
body {
|
|
|
|
| 197 |
}
|
| 198 |
"""
|
| 199 |
|
| 200 |
+
# Load user config
|
| 201 |
user_config = load_config()
|
| 202 |
initial_settings = user_config["settings"]
|
| 203 |
initial_favorites = user_config["favorites"]
|
| 204 |
initial_presets = user_config["presets"]
|
| 205 |
|
| 206 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 207 |
+
# Removed gr.State components to avoid schema issues
|
| 208 |
+
# Use hidden Textbox components to store state instead
|
| 209 |
+
current_lang = gr.Textbox(value=i18n.language, visible=False)
|
| 210 |
+
favorites_state = gr.Textbox(value=json.dumps(initial_favorites), visible=False)
|
| 211 |
+
presets_state = gr.Textbox(value=json.dumps(initial_presets), visible=False)
|
| 212 |
|
| 213 |
header_html = gr.HTML(
|
| 214 |
value=f"""
|
|
|
|
| 221 |
with gr.Tab(i18n("audio_separation_tab"), id="separation_tab"):
|
| 222 |
with gr.Row(equal_height=True):
|
| 223 |
with gr.Column(scale=1, min_width=380):
|
| 224 |
+
with gr.Accordion(i18n("input_model"), open=True):
|
| 225 |
with gr.Tabs():
|
| 226 |
+
with gr.Tab(i18n("upload")):
|
| 227 |
input_audio_file = gr.File(
|
| 228 |
file_types=[".wav", ".mp3", ".m4a", ".mp4", ".mkv", ".flac"],
|
| 229 |
+
elem_classes=["compact-upload", "horizontal"],
|
| 230 |
+
label=i18n("upload_file")
|
| 231 |
)
|
| 232 |
+
with gr.Tab(i18n("path")):
|
| 233 |
+
file_path_input = gr.Textbox(placeholder=i18n("path_placeholder"), label=i18n("file_path"))
|
| 234 |
|
| 235 |
with gr.Row():
|
| 236 |
model_category = gr.Dropdown(
|
|
|
|
| 246 |
value=initial_settings["selected_model"]
|
| 247 |
)
|
| 248 |
|
| 249 |
+
with gr.Accordion(i18n("settings"), open=False):
|
| 250 |
with gr.Row():
|
| 251 |
+
export_format = gr.Dropdown(
|
| 252 |
+
label=i18n("format"),
|
| 253 |
+
choices=['wav FLOAT', 'flac PCM_16', 'flac PCM_24'],
|
| 254 |
+
value=initial_settings["export_format"]
|
| 255 |
+
)
|
| 256 |
+
chunk_size = gr.Dropdown(
|
| 257 |
+
label=i18n("chunk_size"),
|
| 258 |
+
choices=[352800, 485100],
|
| 259 |
+
value=initial_settings["chunk_size"],
|
| 260 |
+
info=i18n("chunk_size_info")
|
| 261 |
+
)
|
|
|
|
|
|
|
| 262 |
|
| 263 |
+
overlap = gr.Slider(
|
| 264 |
+
minimum=2,
|
| 265 |
+
maximum=50,
|
| 266 |
+
step=1,
|
| 267 |
+
label=i18n("overlap"),
|
| 268 |
+
value=initial_settings["overlap"],
|
| 269 |
+
info=i18n("overlap_info")
|
| 270 |
+
)
|
|
|
|
|
|
|
| 271 |
|
| 272 |
+
use_tta = gr.Checkbox(
|
| 273 |
+
label=i18n("tta_boost"),
|
| 274 |
+
info=i18n("tta_info"),
|
| 275 |
+
value=initial_settings["use_tta"]
|
| 276 |
+
)
|
|
|
|
|
|
|
| 277 |
|
| 278 |
+
use_demud_phaseremix_inst = gr.Checkbox(
|
| 279 |
+
label=i18n("phase_fix"),
|
| 280 |
+
info=i18n("phase_fix_info"),
|
| 281 |
+
value=initial_settings["use_demud_phaseremix_inst"]
|
| 282 |
+
)
|
|
|
|
|
|
|
| 283 |
|
| 284 |
+
extract_instrumental = gr.Checkbox(
|
| 285 |
+
label=i18n("instrumental"),
|
| 286 |
+
info=i18n("instrumental_info"),
|
| 287 |
+
value=initial_settings["extract_instrumental"]
|
| 288 |
+
)
|
|
|
|
| 289 |
|
| 290 |
+
use_apollo = gr.Checkbox(
|
| 291 |
+
label=i18n("enhance_with_apollo"),
|
| 292 |
+
value=initial_settings["use_apollo"],
|
| 293 |
+
info=i18n("apollo_enhancement_info")
|
| 294 |
+
)
|
|
|
|
| 295 |
|
| 296 |
with gr.Group(visible=initial_settings["use_apollo"]) as apollo_settings_group:
|
| 297 |
with gr.Row():
|
| 298 |
+
apollo_chunk_size = gr.Slider(
|
| 299 |
+
label=i18n("apollo_chunk_size"),
|
| 300 |
+
minimum=3,
|
| 301 |
+
maximum=25,
|
| 302 |
+
step=1,
|
| 303 |
+
value=initial_settings["apollo_chunk_size"],
|
| 304 |
+
info=i18n("apollo_chunk_size_info")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
)
|
| 306 |
+
apollo_overlap = gr.Slider(
|
| 307 |
+
label=i18n("apollo_overlap"),
|
| 308 |
+
minimum=2,
|
| 309 |
+
maximum=10,
|
| 310 |
+
step=1,
|
| 311 |
+
value=initial_settings["apollo_overlap"],
|
| 312 |
+
info=i18n("apollo_overlap_info")
|
| 313 |
)
|
| 314 |
|
| 315 |
+
apollo_method = gr.Dropdown(
|
| 316 |
+
label=i18n("apollo_processing_method"),
|
| 317 |
+
choices=[i18n("normal_method"), i18n("mid_side_method")],
|
| 318 |
+
value=i18n(initial_settings["apollo_method"])
|
| 319 |
+
)
|
|
|
|
|
|
|
| 320 |
|
| 321 |
+
apollo_normal_model_row = gr.Row(visible=initial_settings["apollo_method"] != "mid_side_method")
|
| 322 |
+
apollo_normal_model = gr.Dropdown(
|
| 323 |
+
label=i18n("apollo_normal_model"),
|
| 324 |
+
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
|
| 325 |
+
value=initial_settings["apollo_normal_model"],
|
| 326 |
+
container=apollo_normal_model_row
|
| 327 |
)
|
| 328 |
|
| 329 |
+
apollo_midside_model_row = gr.Row(visible=initial_settings["apollo_method"] == "mid_side_method")
|
| 330 |
+
apollo_midside_model = gr.Dropdown(
|
| 331 |
+
label=i18n("apollo_mid_side_model"),
|
| 332 |
+
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
|
| 333 |
+
value=initial_settings["apollo_midside_model"],
|
| 334 |
+
container=apollo_midside_model_row
|
|
|
|
|
|
|
|
|
|
| 335 |
)
|
| 336 |
|
| 337 |
+
use_matchering = gr.Checkbox(
|
| 338 |
+
label=i18n("apply_matchering"),
|
| 339 |
+
value=initial_settings.get("use_matchering", False),
|
| 340 |
+
info=i18n("matchering_info")
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
with gr0
|
| 344 |
+
matchering_settings_group = gr.Group(visible=initial_settings.get("use_matchering", True))
|
| 345 |
+
matchering_passes = gr.Slider(
|
| 346 |
+
label=i18n("matchering_passes"),
|
| 347 |
+
minimum=1,
|
| 348 |
+
maximum=5,
|
| 349 |
+
step=1,
|
| 350 |
+
value=initial_settings.get("matchering_passes", 1),
|
| 351 |
+
info=i18n("matchering_passes_info")
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
with gr.Row():
|
| 355 |
process_btn = gr.Button(i18n("process"), variant="primary")
|
| 356 |
clear_old_output_btn = gr.Button(i18n("reset"), variant="secondary")
|
| 357 |
clear_old_output_status = gr.Textbox(label=i18n("status"), interactive=False)
|
| 358 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
with gr.Column(scale=2, min_width=800):
|
| 360 |
with gr.Tabs():
|
| 361 |
+
with gr.Tab(i18n("main_tab")):
|
| 362 |
+
original_audio = gr.Audio(label=i18n("original"), interactive=True)
|
| 363 |
+
with gr.Row():
|
| 364 |
+
vocals_audio = gr.Audio(label=i18n("vocals"), show_download_button=True)
|
| 365 |
+
instrumental_audio = gr.Audio(label=i18n("instrumental_output"), show_download_button=True)
|
| 366 |
+
other_audio = gr.Audio(label=i18n("other"), show_download_button=True)
|
| 367 |
+
|
| 368 |
+
with gr.Tab(i18n("details_tab")):
|
| 369 |
+
with gr.Row():
|
| 370 |
+
male_audio = gr.Audio(label=i18n("male"))
|
| 371 |
+
female_audio = gr.Audio(label=i18n("female"))
|
| 372 |
+
speech_audio = gr.Audio(label=i18n("speech"))
|
| 373 |
+
with gr.Row():
|
| 374 |
+
drum_audio = gr.Audio(label=i18n("drums"))
|
| 375 |
+
bass_audio = gr.Audio(label=i18n("bass"))
|
| 376 |
+
with gr.Row():
|
| 377 |
+
effects_audio = gr.Audio(label=i18n("effects"))
|
| 378 |
+
|
| 379 |
+
with gr.Tab(i18n("advanced_tab")):
|
| 380 |
+
with gr.Row():
|
| 381 |
+
phaseremix_audio = gr.Audio(label=i18n("phase_remix"))
|
| 382 |
+
dry_audio = gr.Audio(label=i18n("dry"))
|
| 383 |
+
with gr.Row():
|
| 384 |
+
music_audio = gr.Audio(label=i18n("music"))
|
| 385 |
+
karaoke_audio = gr.Audio(label=i18n("karaoke"))
|
| 386 |
+
bleed_audio = gr.Audio(label=i18n("bleed"))
|
|
|
|
|
|
|
|
|
|
| 387 |
|
| 388 |
separation_progress_html = gr.HTML(
|
| 389 |
value=f"""
|
| 390 |
+
<div id="custom-progress">
|
| 391 |
+
<div id="progress-label">{i18n("waiting_for_processing")}</div>
|
| 392 |
+
<div style="width: 100%; background-color: #444; border-radius: 5px;">
|
| 393 |
+
<div id="progress-bar" style="width: 0%;"></div>
|
| 394 |
</div>
|
| 395 |
</div>
|
| 396 |
"""
|
|
|
|
| 413 |
)
|
| 414 |
auto_file_path_input = gr.Textbox(
|
| 415 |
label=i18n("enter_file_path"),
|
| 416 |
+
placeholder=i18n("file_path_placeholder")
|
|
|
|
| 417 |
)
|
| 418 |
|
| 419 |
+
with gr.Accordion(i18n("advanced_settings"), open=False):
|
| 420 |
with gr.Row():
|
| 421 |
auto_use_tta = gr.Checkbox(label=i18n("use_tta"), value=False)
|
| 422 |
auto_extract_instrumental = gr.Checkbox(label=i18n("instrumental_only"))
|
|
|
|
| 440 |
value='wav FLOAT'
|
| 441 |
)
|
| 442 |
|
| 443 |
+
auto_use_apollo = gr.Checkbox(
|
| 444 |
+
label=i18n("enhance_with_apollo"),
|
| 445 |
+
value=False,
|
| 446 |
+
info=i18n("apollo_enhancement_info")
|
| 447 |
+
)
|
|
|
|
| 448 |
|
| 449 |
with gr.Group(visible=False) as auto_apollo_settings_group:
|
| 450 |
with gr.Row():
|
| 451 |
+
auto_apollo_chunk_size = gr.Slider(
|
| 452 |
+
label=i18n("apollo_chunk_size"),
|
| 453 |
+
minimum=3,
|
| 454 |
+
maximum=25,
|
| 455 |
+
step=1,
|
| 456 |
+
value=19,
|
| 457 |
+
info=i18n("apollo_chunk_size_info")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
)
|
| 459 |
+
auto_apollo_overlap = gr.Slider(
|
| 460 |
+
label=i18n("apollo_overlap"),
|
| 461 |
+
minimum=2,
|
| 462 |
+
maximum=10,
|
| 463 |
+
step=1,
|
| 464 |
+
value=2,
|
| 465 |
+
info=i18n("apollo_overlap_info")
|
| 466 |
)
|
| 467 |
|
| 468 |
+
auto_apollo_method = gr.Dropdown(
|
| 469 |
+
label=i18n("apollo_processing_method"),
|
| 470 |
+
choices=[i18n("normal_method"), i18n("mid_side_method")],
|
| 471 |
+
value=i18n("normal_method")
|
| 472 |
+
)
|
|
|
|
|
|
|
| 473 |
|
| 474 |
+
auto_apollo_normal_model_row = gr.Row(visible=True)
|
| 475 |
+
auto_apollo_normal_model = gr.Dropdown(
|
| 476 |
+
label=i18n("apollo_normal_model"),
|
| 477 |
+
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
|
| 478 |
+
value="Apollo Universal Model",
|
| 479 |
+
container=auto_apollo_normal_model_row
|
| 480 |
)
|
| 481 |
|
| 482 |
+
auto_apollo_midside_model_row = gr.Row(visible=False)
|
| 483 |
+
auto_apollo_midside_model = gr.Dropdown(
|
| 484 |
+
label=i18n("apollo_mid_side_model"),
|
| 485 |
+
choices=["MP3 Enhancer", "Lew Vocal Enhancer", "Lew Vocal Enhancer v2 (beta)", "Apollo Universal Model"],
|
| 486 |
+
value="Apollo Universal Model",
|
| 487 |
+
container=auto_apollo_midside_model_row
|
| 488 |
+
)
|
| 489 |
+
|
| 490 |
+
auto_use_matchering = gr.Checkbox(
|
| 491 |
+
label=i18n("apply_matchering"),
|
| 492 |
+
value=False,
|
| 493 |
+
info=i18n("matchering_info")
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
with gr.Group(visible=False) as auto_matchering_settings_group:
|
| 497 |
auto_matchering_passes = gr.Slider(
|
| 498 |
label=i18n("matchering_passes"),
|
| 499 |
minimum=1,
|
| 500 |
maximum=5,
|
| 501 |
step=1,
|
| 502 |
value=1,
|
| 503 |
+
info=i18n("matchering_passes_info")
|
|
|
|
| 504 |
)
|
| 505 |
|
| 506 |
with gr.Group():
|
|
|
|
| 518 |
multiselect=True
|
| 519 |
)
|
| 520 |
|
| 521 |
+
preset_dropdown = gr.Dropdown(
|
| 522 |
+
label=i18n("select_preset"),
|
| 523 |
+
choices=list(initial_presets.keys()),
|
| 524 |
+
value=None,
|
| 525 |
+
allow_custom_value=False
|
| 526 |
+
)
|
|
|
|
|
|
|
| 527 |
with gr.Row():
|
| 528 |
preset_name_input = gr.Textbox(
|
| 529 |
label=i18n("preset_name"),
|
| 530 |
+
placeholder=i18n("enter_preset_name")
|
|
|
|
| 531 |
)
|
| 532 |
save_preset_btn = gr.Button(i18n("save_preset"), variant="secondary", scale=0)
|
| 533 |
delete_preset_btn = gr.Button(i18n("delete_preset"), variant="secondary", scale=0)
|
|
|
|
| 535 |
|
| 536 |
with gr.Group():
|
| 537 |
ensemble_settings_header = gr.Markdown(f"### {i18n('ensemble_settings')}")
|
| 538 |
+
auto_ensemble_type = gr.Dropdown(
|
| 539 |
+
label=i18n("method"),
|
| 540 |
+
choices=['avg_wave', 'median_wave', 'min_wave', 'max_wave',
|
| 541 |
+
'avg_fft', 'median_fft', 'min_fft', 'max_fft'],
|
| 542 |
+
value=initial_settings["auto_ensemble_type"]
|
| 543 |
+
)
|
|
|
|
| 544 |
|
| 545 |
ensemble_recommendation = gr.Markdown(i18n("recommendation"))
|
| 546 |
|
| 547 |
auto_process_btn = gr.Button(i18n("start_processing"), variant="primary")
|
| 548 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
with gr.Column():
|
| 550 |
with gr.Tabs():
|
| 551 |
+
with gr.Tab(i18n("original_audio_tab")):
|
| 552 |
original_audio2 = gr.Audio(
|
| 553 |
label=i18n("original_audio"),
|
| 554 |
+
interactive=True,
|
|
|
|
| 555 |
elem_id="original_audio_player"
|
| 556 |
)
|
| 557 |
+
with gr.Tab(i18n("ensemble_result_tab")):
|
| 558 |
auto_output_audio = gr.Audio(
|
| 559 |
label=i18n("output_preview"),
|
| 560 |
show_download_button=True,
|
| 561 |
+
interactive=True
|
| 562 |
)
|
| 563 |
refresh_output_btn = gr.Button(i18n("refresh_output"), variant="secondary")
|
| 564 |
|
| 565 |
ensemble_progress_html = gr.HTML(
|
| 566 |
value=f"""
|
| 567 |
+
<div id="custom-progress">
|
| 568 |
+
<div id="progress-label">{i18n("waiting_for_processing")}</div>
|
| 569 |
+
<div style="width: 100%; background-color: #444; border-radius: 5px;">
|
| 570 |
+
<div id="progress-bar" style="width: 0%;"></div>
|
| 571 |
</div>
|
| 572 |
</div>
|
| 573 |
"""
|
|
|
|
| 578 |
placeholder=i18n("waiting_for_processing"),
|
| 579 |
visible=False
|
| 580 |
)
|
| 581 |
+
|
| 582 |
with gr.Tab(i18n("download_sources_tab"), id="download_tab"):
|
| 583 |
with gr.Row():
|
| 584 |
with gr.Column():
|
|
|
|
| 601 |
with gr.Tab(i18n("manual_ensemble_tab"), id="manual_ensemble_tab"):
|
| 602 |
with gr.Row(equal_height=True):
|
| 603 |
with gr.Column(scale=1, min_width=400):
|
| 604 |
+
with gr.Accordion(i18n("input_sources"), open=True):
|
| 605 |
with gr.Row():
|
| 606 |
refresh_btn = gr.Button(i18n("refresh"), variant="secondary", size="sm")
|
| 607 |
ensemble_type = gr.Dropdown(
|
|
|
|
| 629 |
|
| 630 |
with gr.Column(scale=2, min_width=800):
|
| 631 |
with gr.Tabs():
|
| 632 |
+
with gr.Tab(i18n("result_preview_tab")):
|
| 633 |
ensemble_output_audio = gr.Audio(
|
| 634 |
label=i18n("ensembled_output"),
|
| 635 |
+
interactive=True,
|
| 636 |
show_download_button=True,
|
| 637 |
elem_id="output-audio"
|
| 638 |
)
|
| 639 |
+
with gr.Tab(i18n("processing_log_tab")):
|
| 640 |
with gr.Accordion(i18n("processing_details"), open=True, elem_id="log-accordion"):
|
| 641 |
ensemble_status = gr.Textbox(
|
| 642 |
label="",
|
|
|
|
| 646 |
max_lines=20,
|
| 647 |
elem_id="log-box"
|
| 648 |
)
|
| 649 |
+
ensemble_process_btn = gr.Button(
|
| 650 |
+
i18n("process_ensemble"),
|
| 651 |
+
variant="primary",
|
| 652 |
+
size="sm",
|
| 653 |
+
elem_id="process-btn"
|
| 654 |
+
)
|
| 655 |
+
|
| 656 |
+
# Event handlers
|
| 657 |
+
def update_favorite_button(model, favorites_json):
|
| 658 |
+
favorites = json.loads(favorites_json)
|
| 659 |
+
cleaned_model = clean_model(model) if model else None
|
| 660 |
+
is_favorited = cleaned_model in favorites if cleaned_model else False
|
| 661 |
+
return gr.update(value=i18n("remove_favorite") if is_favorited else i18n("add_favorite"))
|
| 662 |
+
|
| 663 |
+
def toggle_favorite(model, favorites_json):
|
| 664 |
+
favorites = json.loads(favorites_json)
|
| 665 |
+
if not model:
|
| 666 |
+
return json.dumps(favorites), gr.update(), gr.update()
|
| 667 |
+
cleaned_model = clean_model(model)
|
| 668 |
+
is_favorited = cleaned_model in favorites
|
| 669 |
+
new_favorites = update_favorites(favorites, cleaned_model, add=not is_favorited)
|
| 670 |
+
save_config(new_favorites, load_config()["settings"], load_config()["presets"])
|
| 671 |
+
category = model_category.value
|
| 672 |
+
return (
|
| 673 |
+
json.dumps(new_favorites),
|
| 674 |
+
gr.update(choices=update_model_dropdown(category, favorites=new_favorites)["choices"]),
|
| 675 |
+
gr.update(value=i18n("add_favorite") if is_favorited else i18n("remove_favorite"))
|
| 676 |
+
)
|
| 677 |
+
|
| 678 |
+
model_dropdown.change(
|
| 679 |
+
fn=update_favorite_button,
|
| 680 |
+
inputs=[model_dropdown, favorites_state],
|
| 681 |
+
outputs=favorite_button
|
| 682 |
+
)
|
| 683 |
+
|
| 684 |
+
favorite_button.click(
|
| 685 |
+
fn=toggle_favorite,
|
| 686 |
+
inputs=[model_dropdown, favorites_state],
|
| 687 |
+
outputs=[favorites_state, model_dropdown, favorite_button]
|
| 688 |
+
)
|
| 689 |
+
|
| 690 |
+
use_apollo.change(
|
| 691 |
+
fn=lambda x: gr.update(visible=x),
|
| 692 |
+
inputs=use_apollo,
|
| 693 |
+
outputs=apollo_settings_group
|
| 694 |
+
)
|
| 695 |
+
|
| 696 |
+
use_matchering.change(
|
| 697 |
+
fn=lambda x: gr.update(visible=x),
|
| 698 |
+
inputs=use_matchering,
|
| 699 |
+
outputs=matchering_settings_group
|
| 700 |
+
)
|
| 701 |
+
|
| 702 |
+
apollo_method.change(
|
| 703 |
+
fn=lambda x: [
|
| 704 |
+
gr.update(visible=x != i18n("mid_side_method")),
|
| 705 |
+
gr.update(visible=x == i18n("mid_side_method")),
|
| 706 |
+
"Apollo Universal Model" if x == i18n("mid_side_method") else None
|
| 707 |
+
],
|
| 708 |
+
inputs=apollo_method,
|
| 709 |
+
outputs=[apollo_normal_model_row, apollo_midside_model_row, apollo_normal_model]
|
| 710 |
+
)
|
| 711 |
+
|
| 712 |
+
def load_preset(preset_name, presets_json, category, favorites_json):
|
| 713 |
+
presets = json.loads(presets_json)
|
| 714 |
+
favorites = json.loads(favorites_json)
|
| 715 |
+
if preset_name and preset_name in presets:
|
| 716 |
+
preset = presets[preset_name]
|
| 717 |
+
favorite_models = [f"{model} ⭐" if model in favorites else model for model in preset["models"]]
|
| 718 |
+
preset_category = preset.get("auto_category_dropdown", category)
|
| 719 |
+
model_choices = update_model_dropdown(preset_category, favorites=favorites)["choices"]
|
| 720 |
+
logging.debug(f"Preset '{preset_name}' loaded with models: {favorite_models}, category: {preset_category}")
|
| 721 |
+
return (
|
| 722 |
+
gr.update(value=preset_category),
|
| 723 |
+
gr.update(choices=model_choices, value=favorite_models),
|
| 724 |
+
gr.update(value=preset["ensemble_method"])
|
| 725 |
+
)
|
| 726 |
+
logging.debug(f"Preset '{preset_name}' not found.")
|
| 727 |
+
return gr.update(), gr.update(), gr.update()
|
| 728 |
+
|
| 729 |
+
def sync_presets():
|
| 730 |
+
config = load_config()
|
| 731 |
+
return json.dumps(config["presets"]), gr.update(choices=list(config["presets"].keys()), value=None)
|
| 732 |
+
|
| 733 |
+
preset_dropdown.change(
|
| 734 |
+
fn=load_preset,
|
| 735 |
+
inputs=[preset_dropdown, presets_state, auto_category_dropdown, favorites_state],
|
| 736 |
+
outputs=[auto_category_dropdown, selected_models, auto_ensemble_type]
|
| 737 |
+
)
|
| 738 |
+
|
| 739 |
+
def handle_save_preset(preset_name, models, ensemble_method, presets_json, favorites_json, auto_category_dropdown):
|
| 740 |
+
presets = json.loads(presets_json)
|
| 741 |
+
favorites = json.loads(favorites_json)
|
| 742 |
+
if not preset_name:
|
| 743 |
+
return gr.update(), json.dumps(presets), i18n("no_preset_name_provided")
|
| 744 |
+
if not models and not favorites:
|
| 745 |
+
return gr.update(), json.dumps(presets), i18n("no_models_selected_for_preset")
|
| 746 |
+
new_presets = save_preset(
|
| 747 |
+
presets,
|
| 748 |
+
preset_name,
|
| 749 |
+
models,
|
| 750 |
+
ensemble_method,
|
| 751 |
+
auto_category_dropdown=auto_category_dropdown
|
| 752 |
+
)
|
| 753 |
+
save_config(favorites, load_config()["settings"], new_presets)
|
| 754 |
+
logging.debug(f"Preset dropdown updated with choices: {list(new_presets.keys())}")
|
| 755 |
+
return gr.update(choices=list(new_presets.keys()), value=None), json.dumps(new_presets), i18n("preset_saved").format(preset_name)
|
| 756 |
+
|
| 757 |
+
save_preset_btn.click(
|
| 758 |
+
fn=handle_save_preset,
|
| 759 |
+
inputs=[preset_name_input, selected_models, auto_ensemble_type, presets_state, favorites_state, auto_category_dropdown],
|
| 760 |
+
outputs=[preset_dropdown, presets_state]
|
| 761 |
+
)
|
| 762 |
+
|
| 763 |
+
def handle_delete_preset(preset_name, presets_json):
|
| 764 |
+
presets = json.loads(presets_json)
|
| 765 |
+
if not preset_name or preset_name not in presets:
|
| 766 |
+
return gr.update(), json.dumps(presets)
|
| 767 |
+
new_presets = delete_preset(presets, preset_name)
|
| 768 |
+
save_config(load_config()["favorites"], load_config()["settings"], new_presets)
|
| 769 |
+
return gr.update(choices=list(new_presets.keys()), value=None), json.dumps(new_presets)
|
| 770 |
+
|
| 771 |
+
delete_preset_btn.click(
|
| 772 |
+
fn=handle_delete_preset,
|
| 773 |
+
inputs=[preset_dropdown, presets_state],
|
| 774 |
+
outputs=[preset_dropdown, presets_state]
|
| 775 |
+
)
|
| 776 |
+
|
| 777 |
+
refresh_presets_btn.click(
|
| 778 |
+
fn=sync_presets,
|
| 779 |
+
inputs=[],
|
| 780 |
+
outputs=[presets_state, preset_dropdown]
|
| 781 |
+
)
|
| 782 |
+
|
| 783 |
+
auto_use_apollo.change(
|
| 784 |
+
fn=lambda x: gr.update(visible=x),
|
| 785 |
+
inputs=auto_use_apollo,
|
| 786 |
+
outputs=auto_apollo_settings_group
|
| 787 |
+
)
|
| 788 |
+
|
| 789 |
+
auto_use_matchering.change(
|
| 790 |
+
fn=lambda x: gr.update(visible=x),
|
| 791 |
+
inputs=auto_use_matchering,
|
| 792 |
+
outputs=auto_matchering_settings_group
|
| 793 |
+
)
|
| 794 |
+
|
| 795 |
+
auto_apollo_method.change(
|
| 796 |
+
fn=lambda x: [
|
| 797 |
+
gr.update(visible=x != i18n("mid_side_method")),
|
| 798 |
+
gr.update(visible=x == i18n("mid_side_method")),
|
| 799 |
+
"Apollo Universal Model" if x == i18n("mid_side_method") else None
|
| 800 |
+
],
|
| 801 |
+
inputs=auto_apollo_method,
|
| 802 |
+
outputs=[auto_apollo_normal_model_row, auto_apollo_midside_model_row, auto_apollo_normal_model]
|
| 803 |
+
)
|
| 804 |
|
| 805 |
def save_settings_on_process(*args):
|
| 806 |
apollo_method_value = args[11]
|
|
|
|
| 833 |
|
| 834 |
def save_auto_ensemble_settings(*args):
|
| 835 |
settings = load_config()["settings"]
|
| 836 |
+
settings["auto_Ensemble_type"] = args[7]
|
| 837 |
settings["use_matchering"] = args[14]
|
| 838 |
settings["matchering_passes"] = args[15]
|
| 839 |
save_config(load_config()["favorites"], settings, load_config()["presets"])
|
|
|
|
| 840 |
output_audio, status, progress_html = None, i18n("waiting_for_processing"), ensemble_progress_html.value
|
| 841 |
for update in auto_ensemble_process(*args):
|
| 842 |
if isinstance(update, tuple) and len(update) == 3:
|
|
|
|
| 899 |
cleaned_args[1] = clean_model(cleaned_args[1]) if cleaned_args[1] else None
|
| 900 |
cleaned_args[17] = clean_model(cleaned_args[17]) if cleaned_args[17] else None
|
| 901 |
for name, value in zip(input_names, cleaned_args):
|
| 902 |
+
logging.debug(f"UI Input - {name}: {value}")
|
| 903 |
return args
|
| 904 |
|
| 905 |
process_btn.click(
|
|
|
|
| 958 |
refresh_btn.click(fn=update_file_list, outputs=file_dropdown)
|
| 959 |
ensemble_process_btn.click(fn=ensemble_audio_fn, inputs=[file_dropdown, ensemble_type, weights_input], outputs=[ensemble_output_audio, ensemble_status])
|
| 960 |
|
| 961 |
+
return demo
|