Repository navigation
Add admin-only lotto ticket counter: photo labeling site + Mac training pipeline - #38
Merged
Merged
Conversation
Upload photos (phone or desktop), then label each one in the browser: rotate it upright, draw a box around every ticket number, type the number. Originals are stored untouched; rotation and boxes are saved alongside, so labels can always be fixed. New uploads reuse the last photo's rotation and box positions, and splits (70/15/15) are assigned per calendar day so shots of one scene never straddle train and test. The dashboard shows progress toward three milestones (baseline OCR check, first model, solid model) with a days-left estimate at 2 photos/day. The server does no image processing and needs no GPU: /lotto/export.zip hands originals + manifest.jsonl to the Mac, where scripts/lotto/ crops, scores off-the-shelf OCR, trains a small CRNN on the Apple GPU (MPS), and writes predictions.json, which /lotto/predictions imports to pre-fill boxes. Full plan in docs/lotto-training.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
A verification run on 258 synthetic training numbers reached 83% on test, after the usual CTC plateau for the first ~20 epochs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
The goal is a count of tickets per price ($5, $10, $20, ...) from one photo of the display, not reading ticket numbers. Every ticket shows its price in its top-left corner, so each visible corner is one ticket. Labeling: pick a value and tap each price corner; a live tally shows the count per value. New photos start empty (ticket positions change daily) and a photo can hold up to 400 boxes. Dashboard: milestones count labeled photos and say how much of each goal the "To label" backlog covers, so photos can be uploaded for weeks and labeled later. Shows boxed tickets per value, flags rare values, and once predictions are uploaded, how often the model's count was exactly right. Mac side: prepare_dataset.py also writes a YOLO dataset; new train_detector.py fine-tunes a one-class corner detector; the CRNN now reads the value in each corner; predict.py detects, reads and tallies, and its predictions pre-box waiting photos (model output is stored apart from human labels, which are never overwritten). baseline_ocr.py --count scores Apple Vision on whole photos first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
A test run showed every $30 read as $20: the val split held no $30, scored 100% at epoch 14, and that early checkpoint was kept. Ties now keep the later checkpoint, and train_crnn.py warns when val/test lack a value seen in train. predict.py sorts tallies numerically; the guide no longer claims rare values always come free (a digit unique to one value, like the 3 of $30, needs its own examples). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
Value buttons now match the Store Accounting tool ($1, $2, $3, $4, $5, $7, $10, $20, $30, $50, $100), and values can be typed on the keyboard (1 then 0 for $10; a lone 1 waits briefly for $10/$100). A whole-case photo holds ~250 tickets with price corners ~25 px tall: too small to label comfortably or to detect after downscaling. The page and guide now recommend one photo per tray (~60 tickets, corners ~2.5x bigger); the estimate assumes 4 tray photos a day. Tested: 300 boxes on one photo load in under 0.3 s and save fine, so whole-case photos still work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
The Lotto tab is gone from the top navigation; an "Admin tools" card on the (already admin-only) MGMT page links to it, and MGMT stays highlighted while on lotto pages. Hiding the link isn't access control, so every /lotto route now uses admin_required: a normal user typing /lotto is sent to the login page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
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: 601c05d228
ℹ️ 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".
HEIC uploads passed the image/* check, but the Mac scripts open photos with plain Pillow, so prepare_dataset.py would abort on the first HEIC photo. The upload page now converts HEIC/HEIF to full-quality JPEG in the browser (capped at 16 MP for the iOS canvas limit) and drops, with a message, any HEIC the browser can't decode. The server no longer trusts the declared type: it sniffs the bytes, stores only JPEG/PNG/WebP with the sniffed type, and refuses HEIC with instructions (Safari, or iPhone "Most Compatible"). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
CI pins ruff 0.15.20, where PLR0917 isn't enabled, so the "noqa: PLR0913, PLR0917" comments failed with RUF100 (unused noqa). Newer ruff does enable PLR0917. Making the trailing parameters of write_yolo_image() and count_check() keyword-only satisfies PLR0917 on both versions, so the noqa only needs PLR0913. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012k19dCKBK4J2UdDMJd5gLv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Collect and label photos of the scratch-ticket display on the website, then train a model on the Mac that counts tickets per value ($1, $2, $3, $4, $5, $7, $10, $20, $30, $50, $100) from a photo. Each ticket shows its price in its top-left corner, so each visible corner is one ticket.
Website (
/lotto, admin-only, linked from an "Admin tools" card on MGMT)10= $10)/lotto/export.zipgives the originals plusmanifest.jsonl./lotto/predictionsimports the model output: waiting photos get pre-filled, and human labels are never overwritten (model output is stored in a separatemodel_jsoncolumn).Mac scripts (
scripts/lotto/, PyTorch on Apple GPU)prepare_dataset.py: export zip → YOLO dataset + value cropsbaseline_ocr.py --count: scores Apple Vision on whole photos before any trainingtrain_detector.py: fine-tunes a one-class YOLO "price corner" detectortrain_crnn.py: CRNN + CTC reader for the value in each corner (learns digits, so rare values borrow from common ones)predict.py: detect → read → tally, writespredictions.jsonFull plan, photo tips (one photo per tray), labeling rules and timeline:
docs/lotto-training.md.Deploy
Testing
pytest -qpasses. Total coverage is 86% (was 84%),src/safe_family/lotto/lotto.pyis at 99%, andhelpers.pyis unchanged at 95%.ruff check .is clean.tests/test_lotto.pycovers upload/dedupe, labeling and drafts, export, predictions import, progress math, and access control (a normal user is redirected from every/lottoroute, and the nav has no Lotto link).train_crnn.pynow warns when val/test lack a value.Generated by Claude Code