Fix webui.py validation: return after the warning instead of falling through to inference - #1948
Open
Linxiushen wants to merge 1 commit into
Open
Linxiushen wants to merge 1 commit into
Linxiushen wants to merge 1 commit into
Conversation
…through to inference
generate_audio() checks the required inputs for each mode, shows a
gr.Warning and yields one frame of silence when something is missing, but
never returns, so the generator keeps going and calls the model anyway:
- '预训练音色' with no available voice continues into
inference_sft('') and crashes with KeyError: ''
- '3s极速复刻' / '跨语种复刻' without a prompt wav continues into
load_wav(None) and crashes with TypeError
- '3s极速复刻' with an empty prompt text runs zero-shot inference with an
empty prompt instead of stopping
- '自然语言控制' with an empty instruct text runs instruct inference with
an empty instruction (and asserts on CosyVoice2/3)
Add a bare `return` after each of the six warning yields so the warning
is the outcome. Well-formed inputs are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
generate_audio()inwebui.pyvalidates the required inputs for each mode, shows agr.Warning(...)and yields one frame of silence when something is missing, but never returns. The generator keeps going after the warning and calls the model with the invalid inputs anyway:预训练音色with no available voice (sft_dropdown == '') continues intoinference_sft('')and crashes withKeyError: ''.3s极速复刻/跨语种复刻without a prompt wav continues intotorchaudio.info(prompt_wav)withprompt_wav=None(webui.py:78) and crashes withTypeError.3s极速复刻with an empty prompt text runs zero-shot inference with an empty prompt instead of stopping.自然语言控制with an empty instruct text runs instruct inference with an empty instruction (on CosyVoice2/3 that hits theassert self.__class__.__name__ == 'CosyVoice').So the user sees the warning and then a traceback, or a result that is not what the warning said would happen.
Fix
Add a bare
returnafter each of the six warning yields, so the warning is the outcome. Thereturnis deliberately bare: in a generator,return (sample_rate, data)would not deliver anything to the UI, whereas the existingyieldof the silent frame followed byreturnkeeps the current placeholder behaviour and simply stops.Verification
Local differential with the model and Gradio calls stubbed, running the pristine and patched
generate_audioside by side over all 4 modes xsft_dropdownxprompt_textxprompt_wavxinstruct_text(64 input combinations), comparing the sequence ofgr.*calls, inference calls, yielded frames and exceptions:Three of those are worth stating plainly because the old code did not crash there but produced a result the warning text says should not happen:
3s极速复刻with empty prompt text (previously ran zero-shot with an empty prompt),自然语言控制with empty instruct text on CosyVoice v1 (previously ran with an empty instruction), and a prompt wav with a sample rate below 16 kHz (previously warned and synthesized anyway; the upload component's label says the rate must not be below 16 kHz, and this branch didreturnbefore 90433f5). All three now stop, matching the warning.No test file is included: the repo has no test infrastructure and CI runs only flake8, which passes on the changed file.
This fix was developed with AI assistance (Claude); the change was reviewed and verified locally before submission.