Apiarist Dev commited on
Commit
be50c21
·
1 Parent(s): e4f30a9

fix: comparison report sentence built from specialist counts (no more mite contradiction)

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -407,6 +407,27 @@ def run_comparison(image: Image.Image):
407
  return left_image, left_html, image, right_html
408
 
409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
  def _cmp_apiarist_card(r: dict, counts: dict) -> str:
411
  q = counts.get("queen", 0)
412
  rows = "".join(
@@ -430,7 +451,7 @@ def _cmp_apiarist_card(r: dict, counts: dict) -> str:
430
  <tbody>{rows}</tbody>
431
  </table>
432
  <p style="margin-top:10px;font-size:0.84rem;color:#d8c298;">
433
- <b>Report:</b> {r.get('notes','')}</p>
434
  <p style="font-size:0.74rem;color:#8fae8f;margin-top:6px;">
435
  Grounded in pixel-level detections from a custom-trained model.</p>
436
  </div>"""
 
407
  return left_image, left_html, image, right_html
408
 
409
 
410
+ def _grounded_report(counts: dict) -> str:
411
+ """Build the report sentence from the specialist counts ONLY, so it can
412
+ never contradict the count table (the VLM prose sometimes invents mites)."""
413
+ q = counts.get("queen", 0)
414
+ b = counts.get("bee", 0)
415
+ d = counts.get("drone", 0)
416
+ v = counts.get("varroa", 0)
417
+ parts = []
418
+ if q:
419
+ parts.append(f"{q} queen confirmed")
420
+ parts.append(f"{b} worker bee{'s' if b != 1 else ''}")
421
+ if d:
422
+ parts.append(f"{d} drone{'s' if d != 1 else ''}")
423
+ sentence = ", ".join(parts) + " detected on this frame. "
424
+ if v == 0:
425
+ sentence += "No varroa mites found."
426
+ else:
427
+ sentence += f"{v} varroa mite{'s' if v != 1 else ''} flagged - monitor closely."
428
+ return sentence
429
+
430
+
431
  def _cmp_apiarist_card(r: dict, counts: dict) -> str:
432
  q = counts.get("queen", 0)
433
  rows = "".join(
 
451
  <tbody>{rows}</tbody>
452
  </table>
453
  <p style="margin-top:10px;font-size:0.84rem;color:#d8c298;">
454
+ <b>Report:</b> {_grounded_report(counts)}</p>
455
  <p style="font-size:0.74rem;color:#8fae8f;margin-top:6px;">
456
  Grounded in pixel-level detections from a custom-trained model.</p>
457
  </div>"""