Refactor (gradio part1) events wiring contracts#652
Conversation
📝 WalkthroughWalkthroughThis PR introduces a new wiring abstraction framework for Gradio event setup. It creates context classes ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
acestep/ui/gradio/events/__init__.py (1)
1-1573: 🛠️ Refactor suggestion | 🟠 MajorModule exceeds 200 LOC — please split into smaller modules.
This file is far beyond the hard cap; consider extracting generation/results wiring and training wiring into separate modules to meet the size constraint and improve maintainability.As per coding guidelines
**/*.py: Target module size: optimal <= 150 LOC, hard cap 200 LOC.🤖 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 1 - 1573, The file is too large; split the big wiring into smaller modules by extracting the generation/results wiring and the training wiring out of setup_event_handlers and setup_training_event_handlers respectively: move the large body that builds generation-related handlers (everything using GenerationWiringContext, gen_h, res_h, build_auto_checkbox_inputs/outputs, build_mode_ui_outputs and the download_existing_js + loops for save/send/score/lrc/convert/etc.) into a new generation_wiring module exposing a function like register_generation_handlers(demo, dit_handler, llm_handler, dataset_handler, dataset_section, generation_section, results_section) and keep setup_event_handlers only as a thin delegator that constructs GenerationWiringContext and calls that function; likewise move the training_section code (TrainingWiringContext usage and all train_h handlers, wrappers, and button bindings) into a new training_wiring module exposing register_training_handlers(demo, dit_handler, llm_handler, training_section) and let setup_training_event_handlers delegate to it; finally update imports to reference the new modules and ensure all referenced symbols (GenerationWiringContext, TrainingWiringContext, gen_h, res_h, train_h, build_auto_checkbox_inputs/outputs, build_mode_ui_outputs, generation_wrapper, training_wrapper, lokr_training_wrapper) are either moved or re-exported so tests/imports keep working.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@acestep/ui/gradio/events/__init__.py`:
- Around line 1-1573: The file is too large; split the big wiring into smaller
modules by extracting the generation/results wiring and the training wiring out
of setup_event_handlers and setup_training_event_handlers respectively: move the
large body that builds generation-related handlers (everything using
GenerationWiringContext, gen_h, res_h, build_auto_checkbox_inputs/outputs,
build_mode_ui_outputs and the download_existing_js + loops for
save/send/score/lrc/convert/etc.) into a new generation_wiring module exposing a
function like register_generation_handlers(demo, dit_handler, llm_handler,
dataset_handler, dataset_section, generation_section, results_section) and keep
setup_event_handlers only as a thin delegator that constructs
GenerationWiringContext and calls that function; likewise move the
training_section code (TrainingWiringContext usage and all train_h handlers,
wrappers, and button bindings) into a new training_wiring module exposing
register_training_handlers(demo, dit_handler, llm_handler, training_section) and
let setup_training_event_handlers delegate to it; finally update imports to
reference the new modules and ensure all referenced symbols
(GenerationWiringContext, TrainingWiringContext, gen_h, res_h, train_h,
build_auto_checkbox_inputs/outputs, build_mode_ui_outputs, generation_wrapper,
training_wrapper, lokr_training_wrapper) are either moved or re-exported so
tests/imports keep working.
Summary
Scope
Added Acestep/ui/gradio/events/wiring/context.py with:
Added Acestep/ui/gradio/events/wiring/init.py re-exports.
Updated Acestep/ui/gradio/events/init.py to consume shared builders for:
Added Acestep/ui/gradio/events/wiring/context_test.py to lock ordering contracts.
No handler behaviour changes.
No interface signature changes for:
No cross-path runtime/hardware changes.
Validation
Code review by GLM5 with no issues.
Unit tests introduced
Unit tests run
Manual UI tests passed
Risk
Summary by CodeRabbit
Refactor
Tests