Skip to content

Studio: redesign Translate with language tabs, growing panes and file uploads - #18293

Merged
shimmyshimmer merged 20 commits into
mainfrom
studio-translate-redesign
Nov 18, 2026
Merged

shimmyshimmer merged 20 commits into
mainfrom
studio-translate-redesign

Conversation

@shimmyshimmer

@shimmyshimmer shimmyshimmer commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

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

  • Each pane has a row of pill tabs: Detect language plus up to three recent source languages, and up to three recent targets. Picking a tab never reorders or drops them; a language from the full list joins at the front.
  • With Detect language selected, the tab reads e.g. "English - Detected".
  • In light mode the selected tab is the white, softly shadowed pill of Studio's other segmented controls.
  • The chevron opens the full list under that pane only, at the pane's exact width and corners: a search row on top, languages in columns, the current one highlighted and ticked.
  • The swap button sits between the two rows.

Panes

  • The page is wider (up to 96rem, following the UI scale).
  • Both panes start at the same height and grow with the longer text until the bottom of the window, then scroll, with the last lines fading while more text is below.
  • A classic page scrollbar no longer narrows them.
  • With the glass theme and a wallpaper, both panes and the model chip frost like the rest of Studio.

Source pane footer

  • Dictate, open file, the character count, a Style · Tone menu and the Translate button.
  • Paste is gone; Ctrl/Cmd+V still works.
  • The count shows only the number typed; the 50,000 limit appears on hover and in a tooltip.
  • An empty box keeps the Translate button as a faded pill.
  • In a narrow pane the count hides and the style menu shortens, so the Translate button is never cut off.

Translation pane footer: read aloud, chat, use as source and copy, at the same size as the source pane's icons.

Voice

  • The mic is always offered. Where this browser cannot dictate, a click explains why or offers local dictation, as in chat.
  • With Detect language, local and custom transcription let the model identify the spoken language (Japanese speech used to come back as English romaji). The browser's own engine cannot detect and keeps the user's language.
  • Read aloud and dictation ask for a regional voice: the user's own region when they list one, else the language's main one (French was read by a Canadian voice on macOS).

Files

  • Open file and drag and drop (anywhere on the page) accept text, PDF, Word, Excel, PowerPoint, OpenDocument, RTF, EPUB, email and images.
  • Documents use the existing /api/rag/extract-text reader.
  • extract-text now 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.
  • While a file is read the text box is read-only and a second drop is refused; a result that arrives after the text was replaced another way is dropped.

Model download

  • A first translation with a model that is not on disk asks first, in the same dialog style as dictation: "Download Hy-MT2 7B?" with its size. A click before the page's model check has answered runs the check itself.
  • Progress stays in the shared downloads toast. The in-page progress bar and the "loading" bar while translating are removed; an empty translation pane shows a short status instead.

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):

  • Tabs keep their order; picking Japanese from the list puts it first; Detect language keeps a tab saved before recent sources existed.
  • The list matches its pane: same x, width, top and corners.
  • Pane heights grow, then cap near the window bottom; the fade shows only while more text is below.
  • A test PDF and DOCX opened into the box, including a PDF dropped outside the box. A PNG without a vision model gave the 422 message.
  • The download dialog appeared for the 7B model (not on disk) and Cancel started nothing.
  • Glass light and dark with a wallpaper: both panes take the page glass fill and blur (computed styles checked).
  • Read aloud with macOS voices: Japanese by Kyoko (ja-JP), French by Jacques (fr-FR), Stop and the end of speech reset the button.
  • Local dictation with Whisper Tiny and a fake microphone: the download prompt, then English and Japanese speech transcribed into the box, Japanese with Detect language.
  • A 1024px window: the source footer fits with the Translate button whole.

npm run typecheck, npm test and npm run build pass. Backend tests/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.py and test_middleware.py pass. Biome reports nothing new compared with main.

Not covered

  • Image reading with a real vision model loaded was not run on this CPU host; it is covered by tests with the model call stubbed. Tesseract is not installed here either.
  • Browser (Web Speech) dictation needs Google's servers and was not run; read aloud through a Studio speech model was not run.
  • The Desktop (Tauri) webview and native file drops were not run from this host.

Screenshots

The page with English detected, recent languages as tabs and every action inside the panes:

Translate page

The selected tab in light mode, before and after:

Selected tab

Glass theme over a wallpaper, light and dark:

Glass light

Glass dark

The full language list opens under its own pane, at the pane's width and corners:

Language list

A model that is not on disk asks before downloading:

Download prompt

shimmyshimmer added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
shimmyshimmer added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
shimmyshimmer added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
shimmyshimmer added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T10:44:52.778334Z fd96bd7 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread studio/backend/routes/rag.py Outdated
Comment on lines +983 to +984
with pymupdf.open(path) as doc:
png = doc[0].get_pixmap(dpi = config.OCR_DPI).tobytes("png")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…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]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: a118f94a4b

ℹ️ 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".

… 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.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 88caea1375

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 18, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +993 to +997
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"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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]
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
shimmyshimmer added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
shimmyshimmer added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
shimmyshimmer added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: fd96bd7f14

ℹ️ 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".

@shimmyshimmer
shimmyshimmer merged commit 9d7d560 into main Nov 18, 2026
@shimmyshimmer
shimmyshimmer deleted the studio-translate-redesign branch November 18, 2026 10:54
danielhanchen added a commit that referenced this pull request Nov 18, 2026
…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.

![Translate page before and after: identical, stable gutter on
both](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/18315/pr18315_before_after_q-ecdc78103391.png)
danielhanchen added a commit that referenced this pull request Nov 18, 2026
…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.
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