Skip to content

Phase 6: local Streamlit UI for the toolkit#6

Merged
mrjunos merged 4 commits into
mainfrom
phase-6-ui
May 20, 2026
Merged

Phase 6: local Streamlit UI for the toolkit#6
mrjunos merged 4 commits into
mainfrom
phase-6-ui

Conversation

@mrjunos

@mrjunos mrjunos commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

Wraps the existing CLI pipeline in a local Streamlit + Plotly app a non-technical user can run end-to-end: prepare data (tray capture + visual cropping), train models with real-time charts, evaluate, predict on a single bean, and view settings.

Closes #5.

What's in

  • ui optional-deps group (streamlit + plotly), almendra ui CLI subcommand, make ui Makefile target.
  • Six pages behind a sidebar radio:
    • 🏠 Home — dataset stats, recent runs, health check, inline wizard.
    • 📷 Tray Capture — side-A / optional side-B uploaders, TraySpec form, side-by-side original ↔ rectified+overlay preview, save crops to data/raw/proprietary_tray/sessions/<id>/.
    • 🧠 Train — form (backbone, epochs, lr, image size, pseudo-views), Start/Stop, live Plotly chart of train_loss + val_macro_f1 tailing outputs/<run>/live_metrics.jsonl. Advanced controls (gated fusion, view-dropout, augmentation) behind an expander.
    • 📊 Evaluate — checkpoint picker, metrics table, confusion-matrix heatmap, mis-classified bean gallery.
    • 🚀 Predict — upload one bean photo, run latest ONNX (prefers INT8), show predicted class + confidence + Top-3 + accept/reject verdict.
    • ⚙️ Settings — canonical taxonomy, data sources, current config, paths.
  • Bilingual ES/EN from v1 — every visible string lives in ui/components/i18n.py. Sidebar radio toggles between languages. Default: Spanish.
  • Live training charts wiringtrain.loop now writes one JSONL line per epoch to a metrics file. Controlled by the ALMENDRA_LIVE_METRICS env var, so the CLI use case is untouched.
  • Decoupled, file-based UI — stateless across reruns; runs, checkpoints, ONNX files and metrics are discovered from disk under outputs/. Anything that writes the same JSONL schema interoperates.

Decisions locked (from issue #5)

Question Choice
Stack Streamlit + Plotly
Language(s) Bilingual ES/EN toggle from v1 (Spanish default)
Wizard / advanced controls Inline wizard on Home, Advanced collapsed on Train

Test plan

  • streamlit.testing.v1.AppTest smoke-renders all 6 pages in ES and EN (12 cases) without exceptions.
  • i18n dictionary check — every key has both languages.
  • Unit tests for the metrics-writer / metrics-reader file protocol.
  • ruff check + ruff format --check clean.
  • 45/45 tests pass in the suites that don't require torch/onnxruntime.
  • One end-to-end manual run from the UI (tray photos in → trained model out) — requires real Arabica capture data; deferred to Phase 3.

Notes for review

  • Training is launched as a subprocess (not in-thread) so the UI can survive long runs without blocking, and so killing the browser tab doesn't kill training.
  • cmd_ui defers the streamlit import until the subcommand is invoked, so the CLI still works without the ui extra installed.
  • All UI image rendering uses use_container_width=True (Streamlit's modern replacement for the deprecated use_column_width).

v2 (Phase 6.1) — out of scope here

  • Dedicated Labelling page with hotkeys + IAA reporting.
  • Export & Bench page.
  • Model-package zip exporter (ONNX + INT8 + model card + manifest snapshot).
  • "Demo mode" using the public Roboflow data baseline.

🤖 Generated with Claude Code

mrjunos and others added 4 commits May 20, 2026 15:18
Wraps the existing CLI pipeline (tray capture, train, eval, predict, settings)
in a Streamlit + Plotly app a non-technical user can drive end-to-end.

Highlights
- New `ui` optional-deps group (streamlit + plotly); `almendra ui` CLI
  subcommand + `make ui` shortcut.
- Six pages behind a sidebar radio: Home (dataset stats + recent runs +
  inline wizard), Tray Capture, Train, Evaluate, Predict, Settings.
- Bilingual ES/EN from day one — every string lives in a central dict;
  toggling languages takes one click. Default: Spanish.
- Live training charts — `train.loop` writes one JSONL line per epoch to
  `outputs/<run>/live_metrics.jsonl` (env-var `ALMENDRA_LIVE_METRICS` lets the
  UI redirect it). The Train page launches training as a subprocess and tails
  the file every ~2 s into a two-line Plotly chart.
- Inline wizard on Home walks Ingest → Train → Eval with sensible defaults;
  advanced controls (gated fusion, view-dropout, augmentation) live behind an
  Advanced expander on the Train page.
- Stateless across reruns — runs, checkpoints, ONNX files and metrics are all
  discovered from disk. Any process that writes the same JSONL schema works
  with the UI.

Tests
- AppTest smoke-renders every page in ES and EN (12 cases) without exceptions.
- i18n dictionary checked for complete bilingual coverage.
- Unit tests for the live-metrics JSONL writer/reader file protocol.
- All 45 tests in the suites that don't require torch/onnxruntime pass; ruff
  + ruff format clean.

Closes #5

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Without streamlit installed, test_ui_smoke.py was being skipped via
pytest.importorskip — the page render tests never ran in CI.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
A dedicated docs/ui.md walks through install, launch, the full E2E test flow
through the six pages, a sanity-check list, and the common troubleshooting
paths. README links to it from the Quickstart.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…s → views

- Add two screenshots (`docs/images/ui-home.png`, `ui-train.png`) so the
  README shows what the app actually looks like.
- Inline launch instructions, the per-extra unlock table, the six-page tour,
  and a 5-minute end-to-end walkthrough into the README itself (docs/ui.md
  stays as the deeper troubleshooting guide).
- Rename `src/almendra/ui/pages/` → `src/almendra/ui/views/` so Streamlit
  does not auto-discover the directory as its multi-page navigation system
  and shadow our custom sidebar radio.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mrjunos mrjunos merged commit d8b791a into main May 20, 2026
1 check passed
@mrjunos mrjunos deleted the phase-6-ui branch May 20, 2026 20:39
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.

Phase 6: Local UI for the toolkit (Streamlit)

1 participant