Skip to content

Comments

Refactor (gradio part2) generation wiring decomposition#653

Merged
ChuxiJ merged 1 commit intoace-step:mainfrom
1larity:sync/pr2-generation-wiring-20260220
Feb 21, 2026
Merged

Refactor (gradio part2) generation wiring decomposition#653
ChuxiJ merged 1 commit intoace-step:mainfrom
1larity:sync/pr2-generation-wiring-20260220

Conversation

@1larity
Copy link
Contributor

@1larity 1larity commented Feb 20, 2026

Summary

  • Functional decomposition of Gradio generation event wiring.
  • Extracts service/init and metadata/text-format wiring into focused modules without changing public event facade interfaces.
  • Keeps behaviour unchanged while reducing complexity in events/init.py for follow-up splits.

Scope

  • Added Acestep/ui/gradio/events/wiring/generation_service_wiring.py for:

    • dataset import wiring
    • service init / tier / LoRA handlers
    • auto-checkbox and visibility handlers
  • Added Acestep/ui/gradio/events/wiring/generation_metadata_wiring.py for:

    • source analyze/transcribe/sample flows
    • reset/instrumental wiring
  • Added Acestep/ui/gradio/events/wiring/generation_text_format_wiring.py for:

    • format caption / format lyrics wiring
  • Added Acestep/ui/gradio/events/wiring/decomposition_contract_test.py for AST-level delegation contract checks.

  • Updated Acestep/ui/gradio/events/init.py to delegate these sections through wiring helpers.

  • Updated Acestep/ui/gradio/events/wiring/init.py exports.

  • No handler behaviour changes.

  • No interface signature changes for:

    • setup_event_handlers(...)
    • setup_training_event_handlers(...)
  • No cross-path runtime/hardware changes.

Validation

Code review by GLM5 with no issues.

Unit tests introduced

  • Acestep/ui/gradio/events/wiring/decomposition_contract_test.py
    • verifies setup_event_handlers delegates to PR2 wiring helpers
    • verifies generation mode .change(...) still binds outputs=mode_ui_outputs

Unit tests run

  • python -m unittest discover -s acestep/ui/gradio/events/wiring -p *_test.py (pass)

Manual UI tests passed

  • App boot smoke passes: UI loads without startup traceback.
  • Service/init wiring:
    • refresh checkpoints
    • config_path model-type updates
    • tier override updates
    • init status/state updates
    • LoRA load/unload/use/scale updates
  • Auto + visibility:
    • auto toggles + reset all auto
    • init_llm negative prompt visibility
    • batch-size audio column visibility
  • Metadata/text flows:
    • convert src to codes
    • analyze / sample / transcribe
    • reset format flag on field edits
    • instrumental checkbox behaviour
    • format caption / format lyrics outputs + auto sync
  • Downstream sanity:
    • mode switching still correct
    • generation output render still correct

Risk

  • Low. This is wiring extraction with contract checks and targeted unit tests.
  • Residual risk remains integration-level event behaviour (pre-existing gap).

Summary by CodeRabbit

  • Refactor

    • Reorganized internal event handling architecture to use a service registration pattern, improving code modularity and maintainability.
    • Simplified UI wiring logic through decomposition of generation service and metadata handlers.
  • Tests

    • Added regression tests to validate event delegation behavior.

@1larity 1larity force-pushed the sync/pr2-generation-wiring-20260220 branch from fb759e8 to 3884224 Compare February 20, 2026 14:45
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

📝 Walkthrough

Walkthrough

This PR refactors the Gradio UI event wiring system by introducing a registration-based architecture. It replaces direct function calls to build helpers with new register_generation_service_handlers and register_generation_metadata_handlers functions, consolidating multiple event-wiring concerns (dataset, service initialization, LoRA, auto-checkboxes, metadata, text formatting) into organized modules while maintaining existing UI behavior.

Changes

Cohort / File(s) Summary
Event Handler Initialization
acestep/ui/gradio/events/__init__.py
Refactored to use new registration-based wiring functions (register_generation_service_handlers, register_generation_metadata_handlers, build_mode_ui_outputs) instead of direct build_auto_checkbox_* calls; significantly reduced file size by delegating wiring logic to specialized modules.
Wiring Module Infrastructure
acestep/ui/gradio/events/wiring/__init__.py
Extended public API exports to include register_generation_metadata_handlers and register_generation_service_handlers, making them available for import from the wiring package.
Service Handler Registration
acestep/ui/gradio/events/wiring/generation_service_wiring.py
New module implementing register_generation_service_handlers to consolidate dataset, service initialization, model config, tier override, LoRA, and auto-checkbox UI wiring; returns auto_checkbox_inputs and auto_checkbox_outputs for downstream usage.
Metadata Handler Registration
acestep/ui/gradio/events/wiring/generation_metadata_wiring.py
New module implementing register_generation_metadata_handlers to wire audio conversion, analysis, instruction updates, reference audio validation, sample/transcribe flows, and format caption reset events; delegates text formatting to register_generation_text_format_handlers.
Text Format Handler Registration
acestep/ui/gradio/events/wiring/generation_text_format_wiring.py
New module implementing register_generation_text_format_handlers to wire caption and lyrics formatting buttons with shared input/output patterns and auto-checkbox reset chains.
Wiring Contract Tests
acestep/ui/gradio/events/wiring/decomposition_contract_test.py
New regression test suite validating that setup_event_handlers delegates to the new registration functions and that generation_mode change handling correctly uses mode_ui_outputs variable through AST-level source inspection.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ChuxiJ

Poem

🐰 A rabbit hops through wiring halls,
Old functions scattered, nested calls,
Now registration brings them peace,
With handlers bound, complexity's ceased.
Refactored flows, so clean and bright,
The Gradio UI shines just right!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: a refactoring of Gradio generation event wiring through decomposition into focused modules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@1larity 1larity marked this pull request as ready for review February 20, 2026 14:46
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
acestep/ui/gradio/events/__init__.py (1)

281-303: Consider iterable unpacking instead of list concatenation.

The static analysis tool (Ruff RUF005) suggests using iterable unpacking for cleaner syntax.

♻️ Suggested change
         outputs=[
             generation_section["src_audio"],
             generation_section["generation_mode"],
             generation_section["lyrics"],
             generation_section["captions"],
-        ] + mode_ui_outputs,
+            *mode_ui_outputs,
+        ],
     )
     results_section[f"send_to_repaint_btn_{btn_idx}"].click(
         fn=lambda audio, lm, ly, cap, cur_mode: res_h.send_audio_to_repaint(
             audio, lm, ly, cap, cur_mode, llm_handler),
         inputs=[
             results_section[f"generated_audio_{btn_idx}"],
             results_section["lm_metadata_state"],
             generation_section["lyrics"],
             generation_section["captions"],
             generation_section["generation_mode"],
         ],
         outputs=[
             generation_section["src_audio"],
             generation_section["generation_mode"],
             generation_section["lyrics"],
             generation_section["captions"],
-        ] + mode_ui_outputs,
+            *mode_ui_outputs,
+        ],
     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@acestep/ui/gradio/events/__init__.py` around lines 281 - 303, Replace the
list concatenation used in the Gradio .click call outputs with iterable
unpacking to satisfy Ruff RUF005: change occurrences where outputs are built as
[generation_section["src_audio"], generation_section["generation_mode"],
generation_section["lyrics"], generation_section["captions"],] + mode_ui_outputs
to use the splat form [generation_section["src_audio"],
generation_section["generation_mode"], generation_section["lyrics"],
generation_section["captions"], *mode_ui_outputs]; apply this to both .click
calls (the one creating the widget with outputs and the
results_section[f"send_to_repaint_btn_{btn_idx}"].click call) so
generation_section and mode_ui_outputs are combined via unpacking instead of
concatenation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@acestep/ui/gradio/events/__init__.py`:
- Around line 281-303: Replace the list concatenation used in the Gradio .click
call outputs with iterable unpacking to satisfy Ruff RUF005: change occurrences
where outputs are built as [generation_section["src_audio"],
generation_section["generation_mode"], generation_section["lyrics"],
generation_section["captions"],] + mode_ui_outputs to use the splat form
[generation_section["src_audio"], generation_section["generation_mode"],
generation_section["lyrics"], generation_section["captions"], *mode_ui_outputs];
apply this to both .click calls (the one creating the widget with outputs and
the results_section[f"send_to_repaint_btn_{btn_idx}"].click call) so
generation_section and mode_ui_outputs are combined via unpacking instead of
concatenation.

@ChuxiJ ChuxiJ merged commit 2bee6f1 into ace-step:main Feb 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants