Repository navigation
Studio: redesign Translate with language tabs, growing panes and file uploads - #18293
Conversation
…es, reads NFD text, and skips a same-language swap [skip ci]
…s, and takes files dropped anywhere on the page
|
@codex review |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94f5605231
ℹ️ 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".
| with pymupdf.open(path) as doc: | ||
| png = doc[0].get_pixmap(dpi = config.OCR_DPI).tobytes("png") |
There was a problem hiding this comment.
Serialize image rendering with the shared MuPDF lock
When an image is uploaded while another request is parsing or OCRing a document, this new rendering path accesses MuPDF without acquiring parsers.MUPDF_LOCK. core/rag/parsers.py explicitly notes that concurrent use of the shared MuPDF context can crash the process, and existing rendering and local OCR helpers use mupdf_serialized for that reason. Since this synchronous endpoint runs in FastAPI's thread pool, concurrent uploads or background ingestion can reach this code simultaneously. Protect the image open/render/close block with the same lock, without holding it during the vision-model network request.
Useful? React with 👍 / 👎.
…language, one file read at a time extract-text decoded images through PyMuPDF, which cannot open WebP and scales by the file's DPI tag: a 72 dpi phone photo went to the vision model at over 50 megapixels and a 600 dpi scan at a sixth of its size. Pillow now decodes them at native pixels, on white, capped at a letter page at OCR_DPI. Picking Detect language dropped a source tab that was never saved as recent (prefs from before recentSources). A drop while a file is still being read is refused like the disabled Open file button.
…e model check answers [skip ci]
…wnload check [skip ci]
…e segmented pill, a file read never overwrites newer edits Both panes and the model chip opt into the page glass hooks, so with a wallpaper they frost like the rest of Studio instead of sitting as a solid box and a flat tint. The selected language tab in light mode is the white, shadowed pill of the other segmented controls; dark keeps its wash. The text box is read-only while a document or image is read, and a result that arrives after the text was replaced (swap, history, dictation) is dropped instead of overwriting it. [skip ci]
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
… the language's region, the mic is always offered With Detect language, local and custom transcription now let the model identify what is spoken; before, Japanese speech came back as English romaji because auto meant the user's own language. The browser engine cannot detect and keeps the user's language. Speech tags carry a region (the user's own when they list one): French was read by the first French voice listed, Canadian on macOS, and recognition got a bare language code. The mic shows even where the browser cannot dictate, so a click explains why or offers local dictation, as in chat. It is disabled while a file is read. The source footer fits a narrow pane: the count hides and the style menu truncates instead of the Translate button being cut off.
|
Codex Review: Didn't find any major issues. Breezy! 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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8820b6472c
ℹ️ 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".
| with Image.open(path) as opened: | ||
| rgba = ImageOps.exif_transpose(opened).convert("RGBA") | ||
| # On white, as PyMuPDF renders it: dark text on a transparent PNG must not turn black on black. | ||
| image = Image.new("RGB", rgba.size, "white") | ||
| image.paste(rgba, mask = rgba.getchannel("A")) |
There was a problem hiding this comment.
Bound image dimensions before allocating full-resolution copies
For large, highly compressed images, the pixel budget is applied only after EXIF transposition, RGBA conversion, creation of a full-size RGB background, and extraction of an alpha channel. A 12,000 × 12,000 PNG can be well below the upload byte limit and Pillow's default decompression-bomb rejection threshold, yet these buffers consume over a gigabyte before resizing, potentially exhausting memory and terminating the backend. Check dimensions and reject excessively large images before these allocations, or downsample before creating the additional full-resolution buffers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fd96bd7: the header size is checked first (over 50 MP is refused before decoding), and the image is shrunk to the page budget before any other copy. A 160 KB 7000 x 7000 PNG peaked at 639 MB before and 285 MB after.
…ne over 50 MP before decoding A highly compressed PNG can be huge in pixels: each full-size copy (EXIF transpose, RGBA, the white background, the alpha channel) came before the resize. The header is checked first, the image is shrunk to the page budget while decoding, and only small copies follow. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
…ad (#18315) ## Translate: keep the stable gutter without a :has() over the chat thread The long-thread composer gate, `tests/studio/playwright_long_thread_gate.py`, fails on `main` since #18293. It fails on every PR that runs it, for example #18062 and #18108, across `Frontend build + bundle sanity`, `Frontend unit tests (Windows)` and `Composer`: ``` FAIL: :has() matching costs 6.7 ms per keystroke at 200 turns, budget 5.0 ms (1.3x over) studio/frontend/src/index.css:5473 (exact text match) main:has(.translate-page) ``` ### Cause #18293 added this rule so a classic scrollbar does not narrow the Translate panes: ```css main:has(.translate-page) { scrollbar-gutter: stable; } ``` The `<main>` it matches is the layout's scroll container, and on the chat page that element holds the whole thread. An unanchored `:has()` there makes Chromium re-walk every descendant on each keystroke. The gate measures exactly that cost, and it grows with the chat. ### Fix The intent is unchanged: while Translate is open, its layout `<main>` keeps a stable gutter. Only the way that element is selected changes. - `translate-page.tsx`: a layout effect marks the layout `<main>` that holds `.translate-page` with `data-translate-page` while the page is mounted, and removes it on unmount. The page's own root is also a `<main>`, so the effect starts from its parent. - `index.css`: `main:has(.translate-page)` becomes `main[data-translate-page]`. An attribute selector costs nothing per keystroke, and the Translate page renders the same. ### Verification **Long-thread gate, run locally on the same host:** | | `:has()` at 40 turns | `:has()` at 200 turns | Selector matching growth | Gate | |---|---|---|---|---| | `main` | 0.76 ms/key | 3.86 ms/key | 2.11x for 5x the turns (limit 2.0x) | FAIL | | this PR | 0.06 ms/key | 0.09 ms/key | 0.38 to 0.45 ms/key | PASS | **Other checks:** - `tests/translate-page.test.ts`: 27 passed. - `npm run typecheck`: no errors. ### Screenshots Translate page at 1366x768, before (`main`) and after (this PR). Each side was built from its own isolated Studio install. Both render the same page, and on both the layout `<main>` reports `scrollbar-gutter: stable`. The page width is 1076 px on both sides. 
…alled (#18381) ## Summary The Uploads job (`tests/studio/rag_upload_ci.py`) fails on ubuntu-latest and windows-latest because `studio/backend/tests/test_rag_extract_text.py` cannot be collected: ``` studio/backend/tests/test_rag_extract_text.py:129: in <module> ("shot.webp", _image("WEBP", (40, 30)), (40, 30)), studio/backend/tests/test_rag_extract_text.py:119: in _image from PIL import Image E ModuleNotFoundError: No module named 'PIL' ``` Seen on the staging run for #18375, on current main. ## Cause #18293 added image uploads to the knowledge-base path. `routes/rag.py` `_image_png` decodes them with Pillow, and `test_rag_extract_text.py` builds its WebP / JPEG / TIFF fixtures with Pillow inside a `parametrize` list, so at collection time. Pillow is a Studio runtime dependency (`no-torch-runtime.txt` pins `pillow==13.0.0` for Python 3.11+), so the route is correct. The Uploads job builds its venv only from `tests/studio/rag_upload_requirements.txt`, which had no Pillow. `test_rag_upload_requirements_cover_ci_imports.py` exists to catch this kind of gap, but it only read imports placed under an `if ... "CI" ...` block, so a function-level `from PIL import Image` went unseen. ## Fix - Pin `pillow==13.0.0` in `rag_upload_requirements.txt`, the runtime version for the job's Python 3.12. It resolves with the rest of the file on both `x86_64-manylinux_2_28` and `x86_64-pc-windows-msvc`. - Widen the guard with a new check. Every third-party import in the files the harness runs (`test_rag_*.py` plus `test_conversation_archive.py`, as `rag_upload_ci.py` lists them) must be installed by the requirements file. The check covers module level and inside functions. - Imports inside `try: ... except ImportError` stay optional. - Local modules (`studio/backend`, `studio/backend/tests`, `tests/_shared`) are skipped. - Import names map to their wheel name where they differ (`PIL` to `pillow`, `fitz` to `pymupdf`, `docx` to `python-docx`, and so on). - A control test asserts that the scan sees the function-level PIL import. Every other third-party import in those files was already pinned, so the widened check adds no further requirements. ## Verification | `rag_upload_requirements.txt` | `test_rag_upload_requirements_cover_ci_imports.py` | |---|---| | without the Pillow pin (main) | `not in rag_upload_requirements.txt: ['test_rag_extract_text.py: PIL']` | | this branch | 4 passed | ruff is clean.
Summary
Translate is laid out like a familiar translation app: language tabs over two side-by-side panes, every action inside the panes, and documents or images can be opened or dropped onto the page.
It builds on #18263 (detected language), which is now in
main, so this diff is the redesign only.Changes
Languages
Panes
Source pane footer
Translation pane footer: read aloud, chat, use as source and copy, at the same size as the source pane's icons.
Voice
Files
/api/rag/extract-textreader.extract-textnow also reads images, through the loaded vision model, else local Tesseract. Images are decoded with Pillow at their own pixels (WebP included, on white, upright), shrunk to a letter page at the OCR DPI, and refused over 50 MP before decoding. When nothing can read one it returns a 422 that says so.Model download
Sidebar: Translate's big BETA chip in the More menu is the small "New" tag Settings uses. On the page, the Beta tag is larger and centred on the title.
New and changed strings are translated for all 25 locales.
Verification
In a running Studio (Chromium; WebKit for the layout and scrollbar checks):
npm run typecheck,npm testandnpm run buildpass. Backendtests/test_rag_extract_text.py(WebP, DPI tags, the pixel budget, transparency, EXIF orientation, the decode cap, Tesseract at 1:1),test_pdf_local_ocr.pyandtest_middleware.pypass. Biome reports nothing new compared withmain.Not covered
Screenshots
The page with English detected, recent languages as tabs and every action inside the panes:
The selected tab in light mode, before and after:
Glass theme over a wallpaper, light and dark:
The full language list opens under its own pane, at the pane's width and corners:
A model that is not on disk asks before downloading: