Repository navigation
Translate: draw the translation over an image - #19032
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d34e119ec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let best = { | ||
| size: low, | ||
| lines: wrapWords(text, width, (s) => measure(s, low)), | ||
| }; |
There was a problem hiding this comment.
Handle text that cannot fit at the minimum font size
For small image text boxes or translations substantially longer than the original, the initial 4px layout can already exceed the available height, but it is returned even when every iteration fails the fit check. For example, a 50×10px box with a three-line translation returns a layout 14.4px tall. Because drawTranslatedBlocks draws those lines without clipping, the translated text spills outside the covered area and can overlap neighboring text or be cut off at the image edge. Handle the no-fitting-size case explicitly rather than returning an unchecked layout.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5200ce8: when nothing fits even at 4px, only the lines the box holds are kept, the last ending in an ellipsis, and every block is drawn clipped to its covered box, so text never spills onto neighbours (covered by a test).
…an ellipsis A translation that does not fit even at the smallest size now keeps only the lines the box holds, ending in an ellipsis, and every block is drawn clipped to its covered box, so it never spills onto neighbouring text. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5200ce8b7e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return translateTexts(options.texts, complete, { | ||
| signal: options.signal, | ||
| onPhase: options.onPhase, | ||
| }); |
There was a problem hiding this comment.
Split oversized OCR blocks before translating them
When Tesseract groups a long paragraph into one block, this path sends the entire block to the model: translateTexts uses subtitleBatches, which limits groups but never splits an individual text. A 3,200-character block therefore produces one 3,200-character request, whereas the main translation splits it into requests of at most 1,000 characters. This bypasses the safeguard documented in translate-text.ts for Hy-MT2 dropping paragraphs from long passages, so the image overlay can silently omit content even when the plain-text translation succeeds. Split oversized blocks with splitForTranslation and recombine their translations before drawing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 48d6391: blocks longer than one passage are split with splitForTranslation and rejoined, shorter ones keep the numbered batches (test asserts no request over 1,000 characters).
A block over one passage (1,000 characters) went to the model whole, which Hy-MT2 can answer with paragraphs missing; it is now split and rejoined like any text, while shorter blocks keep the numbered batches. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…apped sidebar glass frame flag (#19042) ## Summary Two checks are red on `main` itself, so every PR rebased onto it inherits them (`Core` on all three transformers / TRL legs, `Repo tests (CPU, rest)`, `Repo tests (CPU, studio)` and `Frontend build + bundle sanity`). Both reproduce on a clean `main` checkout. | Failing check | Introduced by | Which side was wrong | Fix | |---|---|---|---| | `tests/test_python39_compatibility.py::test_studio_evaluated_unions_do_not_grow` (`36 studio files now evaluate PEP 604 unions on the floor, against 35 recorded`) | #19032 added `studio/backend/tests/test_rag_extract_text_boxes.py` | The new file. `def _tessdata() -> str \| None` is evaluated at definition time, which fails on the Python floor. The ratchet is right not to grow. | `from __future__ import annotations`, as the ratchet asks. | | `tests/studio/test_appearance_coverage.py::test_every_appearance_setting_is_measured_or_allowlisted` (`<html> flag 'data-sidebar-glass-frame' switches on costly CSS ... but no gate mode measures it`) | #18530 added the `data-sidebar-glass-frame` flag and its CSS | Neither the flag nor the guard: the coverage entry was missing. The flag is set only when the sidebar is pinned under the custom window titlebar (`shouldUseCustomWindowTitlebar()`: Tauri on Windows / Linux), so the Chromium gate cannot reach it. | Map it in `ROOT_FLAGS` to an `allow:` reason, the same way `tauri` and `client-windows` are handled. | ## Testing - `tests/test_python39_compatibility.py`, `tests/studio/test_appearance_coverage.py`, `studio/backend/tests/test_rag_extract_text_boxes.py`: 18 passed, 1 skipped (both guards failed on `main` without this change).
Related to #18666
Summary
When an image is opened on the Translate page and Tesseract read its text, the output pane gets a new "Show on image" action. It opens a dialog that paints the translation over the image, Google Lens style: each text block Tesseract found is covered with the colour sampled around it, and the translated text is drawn in its place, auto-sized to the block, in black or white for contrast. "Download image" saves the result as a PNG (
sign.jpgtranslated into French saves assign.fr.png). The plain text translation is unchanged and stays the main result.Backend (opt-in, default byte-identical)
POST /api/rag/extract-texttakes a new optional form fieldboxes(defaultfalse).boxes=trueand a one-page image that Tesseract read, the response gainsblocks: [{text, lines, box: [x0, y0, x1, y1]}], the box as fractions of the image. The blocks come from the same OCR text page as the text (page.get_text("dict")next to the existingpage.get_text("text")), so OCR runs once andtextis identical to today.Frontend
boxesonly for images a browser canvas can draw (png, jpg, webp, gif, bmp). The action shows only while the text box still holds that image's text and the translation is current.translateTexts, factored out oftranslateSubtitles, which now calls it with identical behaviour), through the same model setup as the main translation (prepareTranslation, factored out ofrunTranslation).translate-image-overlay.ts(no app imports): per-channel median of a ring around each box (sampled before any painting), WCAG contrast pick, word wrap that breaks unspaced scripts between characters, and a binary search for the largest font that fits.Scoped out, and why
Tests
tests/test_rag_extract_text_boxes.py:boxes=truereturns Tesseract's blocks; the default call returns the same three keys and uses the old OCR call; a vision-model read gives no blocks; block parsing (lines joined, empty blocks dropped, boxes clamped to the page) and an OCR failure (no text, no blocks) against a fake PyMuPDF page; and a real Tesseract run on a drawn image, skipped unlessTESSDATA_PREFIXhaseng.traineddata. All 6 pass locally with real Tesseract data (PyMuPDF 1.27.2.3's built-in engine).tests/test_rag_extract_text.pypasses excepttest_damaged_document_is_422_and_cleaned_up[broken.docm], which fails the same way onmainin this environment.tests/translate-image-overlay.test.tscovers the median sampling, contrast, wrapping (including CJK), font fitting, block validation, file naming, one numbered batch for the block texts, and the page wiring. Translate tests 94/94, fullnpm testgreen,npm run typecheckclean,npm run i18n:check:strictpasses, eslint reports nothing new on the touched files.Not verified here
Before / after
A sign image opened on Translate, read by Tesseract and translated into French with Hy-MT2 1.8B in a real Studio (CPU). Both sides read and translate the text the same way; after, the result also has a Show on image action:
The Show on image dialog (right) next to the plain result (left):