feat: Refactor code structure to move web-related components to the webui module and update references accordingly

This commit is contained in:
JB
2025-12-21 08:12:48 -08:00
parent 5303dcf681
commit 938e122166
40 changed files with 161 additions and 93 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import signal
import sys
from abogen.utils import load_config, prevent_sleep_end
from abogen.web.app import main as _run_web_ui
from abogen.webui.app import main as _run_web_ui
# Configure Hugging Face Hub behaviour (mirrors legacy GUI defaults).
os.environ.setdefault("HF_HUB_DISABLE_TELEMETRY", "1")
+1 -1
View File
@@ -95,7 +95,7 @@ def create_app(config: Optional[dict[str, Any]] = None) -> Flask:
)
app.extensions["conversion_service"] = service
from abogen.web.routes import (
from abogen.webui.routes import (
main_bp,
jobs_bp,
settings_bp,
+2 -2
View File
@@ -14,7 +14,7 @@ from abogen.kokoro_text_normalization import normalize_for_pipeline
from abogen.normalization_settings import build_apostrophe_config
from abogen.text_extractor import extract_from_path
from abogen.voice_cache import ensure_voice_assets
from abogen.web.conversion_runner import SAMPLE_RATE, SPLIT_PATTERN, _select_device, _to_float32, _resolve_voice, _spec_to_voice_ids
from abogen.webui.conversion_runner import SAMPLE_RATE, SPLIT_PATTERN, _select_device, _to_float32, _resolve_voice, _spec_to_voice_ids
from abogen.utils import load_numpy_kpipeline
@@ -36,7 +36,7 @@ def _resolve_voice_setting(value: str) -> tuple[str, Optional[str], Optional[str
Returns (resolved_voice_spec, profile_name, profile_language).
"""
from abogen.web.routes.utils.voice import resolve_voice_setting
from abogen.webui.routes.utils.voice import resolve_voice_setting
return resolve_voice_setting(value)
+7 -7
View File
@@ -1,10 +1,10 @@
from abogen.web.routes.main import main_bp
from abogen.web.routes.jobs import jobs_bp
from abogen.web.routes.settings import settings_bp
from abogen.web.routes.voices import voices_bp
from abogen.web.routes.entities import entities_bp
from abogen.web.routes.books import books_bp
from abogen.web.routes.api import api_bp
from abogen.webui.routes.main import main_bp
from abogen.webui.routes.jobs import jobs_bp
from abogen.webui.routes.settings import settings_bp
from abogen.webui.routes.voices import voices_bp
from abogen.webui.routes.entities import entities_bp
from abogen.webui.routes.books import books_bp
from abogen.webui.routes.api import api_bp
__all__ = [
"main_bp",
+6 -6
View File
@@ -6,7 +6,7 @@ from pathlib import Path
from flask import Blueprint, request, jsonify, send_file, url_for, current_app
from flask.typing import ResponseReturnValue
from abogen.web.routes.utils.settings import (
from abogen.webui.routes.utils.settings import (
load_settings,
load_integration_settings,
coerce_float,
@@ -22,9 +22,9 @@ from abogen.voice_profiles import (
export_profiles_payload,
normalize_profile_entry,
)
from abogen.web.routes.utils.common import split_profile_spec
from abogen.web.routes.utils.preview import synthesize_preview, generate_preview_audio
from abogen.web.routes.utils.voice import formula_from_profile
from abogen.webui.routes.utils.common import split_profile_spec
from abogen.webui.routes.utils.preview import synthesize_preview, generate_preview_audio
from abogen.webui.routes.utils.voice import formula_from_profile
from abogen.normalization_settings import (
build_llm_configuration,
build_apostrophe_config,
@@ -37,8 +37,8 @@ from abogen.integrations.calibre_opds import (
CalibreOPDSClient,
CalibreOPDSError,
)
from abogen.web.routes.utils.service import get_service
from abogen.web.routes.utils.form import build_pending_job_from_extraction
from abogen.webui.routes.utils.service import get_service
from abogen.webui.routes.utils.form import build_pending_job_from_extraction
from abogen.text_extractor import extract_from_path
from werkzeug.utils import secure_filename
+2 -2
View File
@@ -3,11 +3,11 @@ from typing import Any, Dict
from flask import Blueprint, render_template
from flask.typing import ResponseReturnValue
from abogen.web.routes.utils.settings import (
from abogen.webui.routes.utils.settings import (
load_settings,
load_integration_settings,
)
from abogen.web.routes.utils.voice import template_options
from abogen.webui.routes.utils.voice import template_options
books_bp = Blueprint("books", __name__)
+4 -4
View File
@@ -2,16 +2,16 @@ from typing import Mapping
from flask import Blueprint, request, jsonify, abort, render_template, redirect, url_for
from flask.typing import ResponseReturnValue
from abogen.web.routes.utils.service import require_pending_job, get_service
from abogen.web.routes.utils.entity import (
from abogen.webui.routes.utils.service import require_pending_job, get_service
from abogen.webui.routes.utils.entity import (
refresh_entity_summary,
pending_entities_payload,
upsert_manual_override,
delete_manual_override,
search_manual_override_candidates,
)
from abogen.web.routes.utils.settings import coerce_int, load_settings
from abogen.web.routes.utils.voice import template_options
from abogen.webui.routes.utils.settings import coerce_int, load_settings
from abogen.webui.routes.utils.voice import template_options
from abogen.pronunciation_store import (
delete_override as delete_pronunciation_override,
save_override as save_pronunciation_override,
+7 -7
View File
@@ -6,25 +6,25 @@ from typing import Any, Dict, Optional
from flask import Blueprint, Response, abort, redirect, render_template, request, url_for, send_file
from flask.typing import ResponseReturnValue
from abogen.web.service import (
from abogen.webui.service import (
JobStatus,
load_audiobookshelf_chapters,
build_audiobookshelf_metadata,
)
from abogen.web.routes.utils.service import get_service
from abogen.web.routes.utils.form import render_jobs_panel
from abogen.web.routes.utils.voice import template_options
from abogen.web.routes.utils.epub import (
from abogen.webui.routes.utils.service import get_service
from abogen.webui.routes.utils.form import render_jobs_panel
from abogen.webui.routes.utils.voice import template_options
from abogen.webui.routes.utils.epub import (
job_download_flags,
locate_job_epub,
locate_job_audio,
)
from abogen.web.routes.utils.settings import (
from abogen.webui.routes.utils.settings import (
stored_integration_config,
build_audiobookshelf_config,
coerce_bool,
)
from abogen.web.routes.utils.common import existing_paths
from abogen.webui.routes.utils.common import existing_paths
from abogen.integrations.audiobookshelf import AudiobookshelfClient, AudiobookshelfUploadError
logger = logging.getLogger(__name__)
+5 -5
View File
@@ -7,11 +7,11 @@ from typing import Any, Dict, Optional, cast
from flask import Blueprint, redirect, render_template, request, url_for, jsonify, current_app
from werkzeug.utils import secure_filename
from abogen.web.service import PendingJob, JobStatus
from abogen.web.routes.utils.service import get_service, remove_pending_job, submit_job
from abogen.web.routes.utils.settings import load_settings
from abogen.web.routes.utils.voice import template_options
from abogen.web.routes.utils.form import (
from abogen.webui.service import PendingJob, JobStatus
from abogen.webui.routes.utils.service import get_service, remove_pending_job, submit_job
from abogen.webui.routes.utils.settings import load_settings
from abogen.webui.routes.utils.voice import template_options
from abogen.webui.routes.utils.form import (
normalize_wizard_step,
wants_wizard_json,
render_wizard_partial,
+3 -3
View File
@@ -6,7 +6,7 @@ from typing import Any
from flask import Blueprint, current_app, render_template, request, redirect, url_for, flash, send_file, abort
from flask.typing import ResponseReturnValue
from abogen.web.routes.utils.settings import (
from abogen.webui.routes.utils.settings import (
load_settings,
load_integration_settings,
save_settings,
@@ -19,8 +19,8 @@ from abogen.web.routes.utils.settings import (
_NORMALIZATION_STRING_KEYS,
_DEFAULT_ANALYSIS_THRESHOLD,
)
from abogen.web.routes.utils.voice import template_options
from abogen.web.debug_tts_runner import run_debug_tts_wavs
from abogen.webui.routes.utils.voice import template_options
from abogen.webui.debug_tts_runner import run_debug_tts_wavs
from abogen.debug_tts_samples import DEBUG_TTS_SAMPLES
from abogen.utils import get_user_output_path, load_config
+2 -2
View File
@@ -2,7 +2,7 @@ import time
import uuid
from typing import Any, Dict, Iterable, List, Mapping, Optional
from abogen.web.service import PendingJob
from abogen.webui.service import PendingJob
from abogen.entity_analysis import (
extract_entities,
merge_override,
@@ -16,7 +16,7 @@ from abogen.pronunciation_store import (
save_override as save_pronunciation_override,
search_overrides as search_pronunciation_overrides,
)
from abogen.web.routes.utils.settings import load_settings
from abogen.webui.routes.utils.settings import load_settings
from abogen.heteronym_overrides import extract_heteronym_overrides
def collect_pronunciation_overrides(pending: PendingJob) -> List[Dict[str, Any]]:
+1 -1
View File
@@ -7,7 +7,7 @@ from pathlib import Path
from typing import Any, Dict, Iterable, List, Mapping, Optional, Set, Tuple
from xml.etree import ElementTree as ET
from abogen.web.service import Job, JobStatus
from abogen.webui.service import Job, JobStatus
def _coerce_path(value: Any) -> Optional[Path]:
if isinstance(value, Path):
+7 -7
View File
@@ -5,9 +5,9 @@ from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, cast
from flask import request, render_template, jsonify
from flask.typing import ResponseReturnValue
from abogen.web.service import PendingJob, JobStatus
from abogen.web.routes.utils.service import get_service
from abogen.web.routes.utils.settings import (
from abogen.webui.service import PendingJob, JobStatus
from abogen.webui.routes.utils.service import get_service
from abogen.webui.routes.utils.settings import (
load_settings,
coerce_bool,
coerce_int,
@@ -18,7 +18,7 @@ from abogen.web.routes.utils.settings import (
SAVE_MODE_LABELS,
audiobookshelf_manual_available,
)
from abogen.web.routes.utils.voice import (
from abogen.webui.routes.utils.voice import (
parse_voice_formula,
formula_from_profile,
resolve_voice_setting,
@@ -26,9 +26,9 @@ from abogen.web.routes.utils.voice import (
prepare_speaker_metadata,
template_options,
)
from abogen.web.routes.utils.entity import sync_pronunciation_overrides
from abogen.web.routes.utils.epub import job_download_flags
from abogen.web.routes.utils.common import split_profile_spec
from abogen.webui.routes.utils.entity import sync_pronunciation_overrides
from abogen.webui.routes.utils.epub import job_download_flags
from abogen.webui.routes.utils.common import split_profile_spec
from abogen.utils import calculate_text_length
from abogen.voice_profiles import serialize_profiles, normalize_profile_entry
from abogen.chunking import ChunkLevel, build_chunks_for_chapters
+1 -1
View File
@@ -75,7 +75,7 @@ def generate_preview_audio(
source_text = text
if pronunciation_overrides or manual_overrides or speakers:
try:
from abogen.web import conversion_runner as runner
from abogen.webui import conversion_runner as runner
class _PreviewJob:
def __init__(self):
+1 -1
View File
@@ -1,6 +1,6 @@
from typing import cast
from flask import current_app, abort
from abogen.web.service import ConversionService, PendingJob
from abogen.webui.service import ConversionService, PendingJob
def get_service() -> ConversionService:
return current_app.extensions["conversion_service"]
+1 -1
View File
@@ -15,7 +15,7 @@ from abogen.normalization_settings import (
from abogen.utils import load_config, save_config
from abogen.integrations.calibre_opds import CalibreOPDSClient
from abogen.integrations.audiobookshelf import AudiobookshelfConfig
from abogen.web.routes.utils.common import split_profile_spec
from abogen.webui.routes.utils.common import split_profile_spec
SAVE_MODE_LABELS = {
"save_next_to_input": "Save next to input file",
+3 -3
View File
@@ -4,8 +4,8 @@ import numpy as np
from abogen.speaker_configs import slugify_label
from abogen.speaker_analysis import analyze_speakers
from abogen.web.routes.utils.settings import load_settings, settings_defaults, _DEFAULT_ANALYSIS_THRESHOLD, _CHUNK_LEVEL_OPTIONS, _APOSTROPHE_MODE_OPTIONS, _NORMALIZATION_GROUPS
from abogen.web.routes.utils.common import split_profile_spec
from abogen.webui.routes.utils.settings import load_settings, settings_defaults, _DEFAULT_ANALYSIS_THRESHOLD, _CHUNK_LEVEL_OPTIONS, _APOSTROPHE_MODE_OPTIONS, _NORMALIZATION_GROUPS
from abogen.webui.routes.utils.common import split_profile_spec
from abogen.voice_profiles import (
load_profiles,
serialize_profiles,
@@ -21,7 +21,7 @@ from abogen.constants import (
)
from abogen.speaker_configs import list_configs
from abogen.utils import load_numpy_kpipeline
from abogen.web.conversion_runner import _select_device, _to_float32, SAMPLE_RATE, SPLIT_PATTERN
from abogen.webui.conversion_runner import _select_device, _to_float32, SAMPLE_RATE, SPLIT_PATTERN
_preview_pipeline_lock = threading.RLock()
_preview_pipelines: Dict[Tuple[str, str], Any] = {}
+3 -3
View File
@@ -2,14 +2,14 @@ from typing import Any, Dict, List, Optional
from flask import Blueprint, render_template, request, jsonify, abort, flash, redirect, url_for
from flask.typing import ResponseReturnValue
from abogen.web.routes.utils.voice import (
from abogen.webui.routes.utils.voice import (
template_options,
resolve_voice_setting,
resolve_voice_choice,
parse_voice_formula,
)
from abogen.web.routes.utils.settings import load_settings, coerce_bool
from abogen.web.routes.utils.preview import synthesize_preview
from abogen.webui.routes.utils.settings import load_settings, coerce_bool
from abogen.webui.routes.utils.preview import synthesize_preview
from abogen.speaker_configs import (
list_configs,
get_config,