aboutsummaryrefslogtreecommitdiff
path: root/app/ui/hub.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-09-02 22:53:07 -0400
committerhistoria <historiavg@proton.me>2026-09-02 22:53:07 -0400
commitd04a2c53b926ccde0d582dbf4a7360dc0f072205 (patch)
treed817622c7d32039d293c6b7d3141d40028533b96 /app/ui/hub.py
parent7a7dca313750ee75e0f8a2a5442ca5d78e743294 (diff)
downloadtts-audiobook-generator-d04a2c53b926ccde0d582dbf4a7360dc0f072205.tar.gz
fix: warn before using a likely too-big chunk size for sglang-omni models
Diffstat (limited to 'app/ui/hub.py')
-rw-r--r--app/ui/hub.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/ui/hub.py b/app/ui/hub.py
index 13f17e7..7a6bfcc 100644
--- a/app/ui/hub.py
+++ b/app/ui/hub.py
@@ -1133,6 +1133,32 @@ def _tui_confirm(stdscr) -> Callable:
return confirm
+def _tui_chunk_clamp(stdscr, entry) -> Optional[int]:
+ """The chunk-cap popup for an sglomni run (None = no clamp).
+
+ A model whose catalog entry caps a sub-request below CHUNK_SIZE
+ (Higgs: the server pins each request's prompt plus generation at a
+ fixed window) asks before the run: clamp CHUNK_SIZE for this run,
+ keep it (audio may cut off mid-chunk), or go back to the form. The
+ answer rides the command's kwargs (``chunk_size``) so the converter
+ and its client see it; the config.CHUNK_SIZE setting itself is never
+ rewritten.
+ """
+ if not converter_mod.chunk_clamp_needed(entry):
+ return None
+ words = entry.chunk_words
+ answer = tui.menu(
+ stdscr, "Generation cap",
+ [(f"Set Chunk to {words} (this run)", "clamp"),
+ ("Try anyway", "anyway"),
+ ("Cancel", "cancel")],
+ help_lines=converter_mod.chunk_clamp_message(entry),
+ back_value="cancel")
+ if answer == "cancel":
+ raise _BackToForm()
+ return words if answer == "clamp" else None
+
+
def _check_preflight_plan(stdscr, book_files: list, planned: dict) -> bool:
"""The shared nothing-to-convert flashes; True when there is a plan.
@@ -1180,6 +1206,12 @@ def _preflight(stdscr, cmd: tuple) -> bool:
confirm=_tui_confirm(stdscr))
if not _check_preflight_plan(stdscr, book_files, {"": planned}):
return False
+ if backend == BACKEND_SGLOMNI:
+ entry = sglomni_backend.entry_by_key((kwargs.get("model_id")
+ or "").strip())
+ clamp = _tui_chunk_clamp(stdscr, entry)
+ if clamp is not None:
+ kwargs["chunk_size"] = clamp
kwargs["book_files"] = book_files
kwargs["planned"] = planned
return True