Skip to content

feat(ui): add Svelte frontend for /humanize, LibreTranslate option for Step 4, and Docker startup fixes - #29

Open
eyeofastarte wants to merge 5 commits into
lynote-ai:mainfrom
eyeofastarte:feat/humanizer-ui
Open

feat(ui): add Svelte frontend for /humanize, LibreTranslate option for Step 4, and Docker startup fixes#29
eyeofastarte wants to merge 5 commits into
lynote-ai:mainfrom
eyeofastarte:feat/humanizer-ui

Conversation

@eyeofastarte

Copy link
Copy Markdown

Summary

This PR bundles the last 3 commits:

  • Docker fix so the container actually starts reliably.
  • A proper Svelte UI for the /humanize flow, built and served by FastAPI.
  • Support for self-hosted LibreTranslate as a Step 4 provider in the v1.5 Standard Pipeline (previously Niutrans-only).

Type of Change

  • Bug fix (non-breaking fixes a confirmed issue)
  • New feature (non-breaking adds new behaviour)
  • Breaking change (changes or removes existing behaviour)
  • Refactor / cleanup (behaviour unchanged)
  • Documentation only
  • CI / tooling / configuration

Why

  • The Docker path had dependency/startup issues; the container didn't start up cleanly.
  • There was no first-party UI, so trying /humanize meant curl or Postman.
  • Step 4 hard-required Niutrans. If you didn't have access you were stuck. LibreTranslate gives a self-hosted, free, testable output.

Changes

Docker / runtime

  • docker/Dockerfile now runs the unified entrypoint: uvicorn src.api:app --port 8001.
  • docker-compose.yml healthcheck hits http://localhost:8001/v1/health, so it reflects the v1 app instead of just "the port is open."

Frontend (Svelte)

  • New app under frontend/src/*: text input, method + language pickers, result card, error states.
  • frontend/src/lib/api.js: small API helper that checks status/content-type and throws readable errors when the server returns non-JSON (e.g. a proxy HTML error page) instead of blowing up on res.json().
  • Dockerfile is now multi-stage: builds the frontend and copies dist into /app/static, where FastAPI serves it. One container, no separate dev server in prod.

LibreTranslate Step 4 provider (v1.5 Standard Pipeline)

  • New libretranslate_translate(...) in src/standard/translators.py.
  • src/standard/pipeline.py gets pipeline.step4_provider = "niutrans" | "libretranslate": defaults to Niutrans, so existing setups are unaffected.
  • /v1/config (src/standard/api.py) now exposes step4_provider and libretranslate_base_url: non-sensitive values only.
  • Exports updated in src/standard/__init__.py.
  • config/config.toml documents the new keys: [pipeline] step4_provider and [providers.libretranslate].

Tests

  • tests/test_standard_api.py: route shapes/validation, config redaction, language normalization, legacy bridge reachability, and the new /v1/config fields.
  • tests/test_standard_pipeline.py: Step 4 defaults to Niutrans, switches to LibreTranslate when configured, and the response shape stays the same either way.

Visual / UI changes - REQUIRED if you touched anything that renders

AI Humanizer

@molly554 molly554 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Changes Requested

Tests pass (38/38), code is well-structured overall, but there are a few issues that need fixing before merge.


🔴 Critical: Branch deletes Atlas Cloud provider (#28)

This branch was forked before PR #28 (Atlas Cloud) was merged into main. As a result, merging this PR will remove the Atlas Cloud provider, its env-var fallback, and its 2 tests from llm_client.py and test_llm_client.py.

Fix: Rebase onto current main and resolve conflicts — keep the Atlas Cloud entries.


🟡 Breaking: Port change 8000 → 8001

humanizer.py CLI --serve and docker-compose.yml / Dockerfile all switch from port 8000 to 8001 without a migration note. Existing Docker users will break silently.

Fix: Either keep 8000 (preferred — less churn), or document the port change prominently in the PR description and README.


🟡 Dependencies: fastapi/uvicorn/pydantic added to base requirements.txt

PR #17 was rejected partly for pulling FastAPI into the base dependency set. The pipeline's core use case is CLI — users who just want python -m src.standard.pipeline shouldn't need FastAPI installed.

Fix: Move fastapi, uvicorn[standard], pydantic to setup.py extras:

extras_require={
    "api": ["fastapi>=0.109.0", "uvicorn[standard]>=0.27.0", "pydantic>=2.0.0"],
    ...
}

🟡 API has no authentication

/v1/humanize/standard is open — anyone who can reach the port can burn through your LLM API key. A Docker deployment exposed on a public IP would be a cost risk.

Fix: Add a simple bearer-token check (read from env/config), or at minimum document the risk and recommend running behind a reverse proxy.


🟢 Minor issues

  1. Unused imports in src/standard/api.py: time and Optional are imported but never used — remove them.

  2. _load_config() reads disk on every request: Consider caching with @lru_cache or loading once at startup via FastAPI lifespan. Current approach is fine for low traffic but will add latency under load.

  3. normalize_target_lang() is verbose: The 12-language if-chain and the final fallback target_lang.split("-")[0] do the same thing. The fallback alone covers all cases — the explicit branches are unnecessary.

  4. SPA catch-all route ordering: @app.get("/{full_path:path}") in humanizer.py catches all GET requests when STATIC_DIR exists. This works now because the legacy API only has POST endpoints, but adding a new GET route later would be silently shadowed. Consider using a more specific prefix like @app.get("/app/{full_path:path}").


Summary

The LibreTranslate integration, Svelte UI, and API layer are solid work — good test coverage and clean separation. The main blocker is the rebase conflict that would delete Atlas Cloud. Once that's resolved and the dependency/auth issues are addressed, this is ready to merge.

Wire the language field from HumanizeRequest through to
TranslationChainProcessor so requests like en-US are honored.
Add per-engine normalization (e.g. en-US -> en for Google,
ja -> ja-JP for MyMemory) and update the default chain to use
ja-JP so the MyMemory hop does not fail.
- Bun and Static Svelte Build UI Frontend
- Tests for the v1.5 Standard Pipeline API
@eyeofastarte

Copy link
Copy Markdown
Author

Addressed review items: rebased onto latest main, reverted ports to 8000, moved FastAPI stack to optional api extra, added docker-compose security warning for unauthenticated API exposure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants