aboutsummaryrefslogtreecommitdiff
path: root/app/backends/qwen.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/backends/qwen.py')
-rw-r--r--app/backends/qwen.py98
1 files changed, 61 insertions, 37 deletions
diff --git a/app/backends/qwen.py b/app/backends/qwen.py
index f1e7c79..7fba7e0 100644
--- a/app/backends/qwen.py
+++ b/app/backends/qwen.py
@@ -30,7 +30,7 @@ from backends import (
servers,
)
from converter import config
-from ui import tui
+from ui import taskview, tui
QWEN_PIP_PKG = "qwen-tts"
QWEN_CUSTOMVOICE_MODEL = "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice"
@@ -143,39 +143,61 @@ def _wizard(stdscr, args: argparse.Namespace) -> Optional[dict]:
return tui.Wizard().run(_after_install())
+def _execute_steps(settings: dict) -> List[taskview.TaskStep]:
+ """Build the ordered setup steps for the in-TUI task view.
+
+ The same work ``_execute`` runs on the console, split into named steps so
+ the view can show per-step state and progress. The pip install streams
+ through EMIT and aborts on CANCEL; print()-based steps are captured by
+ the view's stdout redirect.
+ """
+ steps: List[taskview.TaskStep] = []
+
+ if settings["do_install"]:
+ def install(emit, cancel):
+ rc = common.pip_install([QWEN_PIP_PKG], emit=emit, cancel=cancel)
+ if rc != 0:
+ print(f"[WARNING] pip install failed (exit {rc}); install "
+ f"{QWEN_PIP_PKG} manually")
+ else:
+ print(f"[OK] {QWEN_PIP_PKG} installed")
+ return rc
+ steps.append(taskview.TaskStep(f"Install {QWEN_PIP_PKG}", install))
+
+ def sync(emit, cancel):
+ custom_url = common.url_with_port(
+ config.QWEN_API_URL, settings["custom_port"])
+ if custom_url != config.QWEN_API_URL:
+ if common.update_config_value("QWEN_API_URL", custom_url):
+ print(f"[OK] Updated QWEN_API_URL to {custom_url}")
+ else:
+ print("[WARNING] Could not update QWEN_API_URL; edit "
+ "app/converter/config.py by hand")
+ clone_url = common.url_with_port(
+ config.CLONE_API_URL, settings["clone_port"])
+ if clone_url != config.CLONE_API_URL:
+ if common.update_config_value("CLONE_API_URL", clone_url):
+ print(f"[OK] Updated CLONE_API_URL to {clone_url}")
+ else:
+ print("[WARNING] Could not update CLONE_API_URL; edit "
+ "app/converter/config.py by hand")
+ if settings["speaker"] != config.SPEAKER:
+ if common.update_config_value("SPEAKER", settings["speaker"]):
+ print(f"[OK] Updated SPEAKER to {settings['speaker']}")
+ else:
+ print("[WARNING] Could not update SPEAKER; edit "
+ "app/converter/config.py by hand")
+
+ _print_launch_hint(settings["custom_port"], settings["clone_port"])
+ return 0
+ steps.append(taskview.TaskStep("Sync config & ports", sync))
+
+ return steps
+
+
def _execute(settings: dict) -> int:
"""Console tail: install, sync config, advise."""
- if settings["do_install"]:
- rc = common.pip_install([QWEN_PIP_PKG])
- if rc != 0:
- print(f"[WARNING] pip install failed (exit {rc}); install "
- f"{QWEN_PIP_PKG} manually")
- else:
- print(f"[OK] {QWEN_PIP_PKG} installed")
-
- custom_url = common.url_with_port(config.QWEN_API_URL, settings["custom_port"])
- if custom_url != config.QWEN_API_URL:
- if common.update_config_value("QWEN_API_URL", custom_url):
- print(f"[OK] Updated QWEN_API_URL to {custom_url}")
- else:
- print("[WARNING] Could not update QWEN_API_URL; edit "
- "app/converter/config.py by hand")
- clone_url = common.url_with_port(config.CLONE_API_URL, settings["clone_port"])
- if clone_url != config.CLONE_API_URL:
- if common.update_config_value("CLONE_API_URL", clone_url):
- print(f"[OK] Updated CLONE_API_URL to {clone_url}")
- else:
- print("[WARNING] Could not update CLONE_API_URL; edit "
- "app/converter/config.py by hand")
- if settings["speaker"] != config.SPEAKER:
- if common.update_config_value("SPEAKER", settings["speaker"]):
- print(f"[OK] Updated SPEAKER to {settings['speaker']}")
- else:
- print("[WARNING] Could not update SPEAKER; edit "
- "app/converter/config.py by hand")
-
- _print_launch_hint(settings["custom_port"], settings["clone_port"])
- return 0
+ return taskview.run_steps_inline(_execute_steps(settings))
def _print_launch_hint(custom_port: int, clone_port: int) -> None:
@@ -195,16 +217,18 @@ def setup_screen(stdscr) -> int:
The hub drives this as one screen of its own ``tui.Wizard`` stack, so
Esc on the wizard's first screen simply returns here and the hub pops
- back to the menu that launched it. The console tail (pip install /
- config sync) runs under ``tui.suspend`` so the hub's curses session
- stays intact. Returns 0 on completion, 1 when the user aborted.
+ back to the menu that launched it. The setup tail (pip install / config
+ sync) runs inside the TUI task view on this same screen, so the hub's
+ curses session stays intact and the user sees per-step status instead of
+ being dropped to the console. Returns 0 on completion, 1 when the user
+ aborted.
"""
args = build_parser().parse_args([])
settings = _wizard(stdscr, args)
if settings is None:
return 1
- with tui.suspend(stdscr):
- return _execute(settings)
+ return taskview.run_steps(stdscr, "Setting up qwen-tts",
+ _execute_steps(settings))
def run_tui(args: Optional[argparse.Namespace] = None) -> int: