Claude commited on
Commit
b81844c
·
1 Parent(s): 4ee95d7

fix: detected font display, remove reviewer, add noise paste box for NON_STORY_TEXT blocking

Browse files
Files changed (1) hide show
  1. smoke_signal_tab.py +19 -11
smoke_signal_tab.py CHANGED
@@ -2632,7 +2632,7 @@ def get_review_item(idx: int) -> tuple:
2632
  return img_path, item.get("raw_ocr",""), info, len(q_df) - len(pending), len(q_df), font_name_val
2633
 
2634
 
2635
- def save_review_decision(idx: int, final_text: str, action: str, reviewer: str, reason: str, conf_override: bool = False) -> tuple:
2636
  q_df = load_queue_df()
2637
  d_df = load_decisions_df()
2638
  if q_df.empty:
@@ -2666,7 +2666,7 @@ def save_review_decision(idx: int, final_text: str, action: str, reviewer: str,
2666
  "raw_text": raw_text,
2667
  "raw_text_original": raw_text_original,
2668
  "reason_code": reason,
2669
- "reviewer": reviewer or "reviewer",
2670
  "font_name": item.get("font_name", ""),
2671
  "was_correct": was_correct,
2672
  "decided_at": datetime.utcnow().isoformat() + "Z",
@@ -2706,7 +2706,8 @@ def save_review_decision(idx: int, final_text: str, action: str, reviewer: str,
2706
 
2707
  learned_pairs = 0
2708
  if action == "rejected" and str(reason).strip() == "NON_STORY_TEXT":
2709
- noise_text = (final_text.strip() or raw_text.strip())
 
2710
  if noise_text:
2711
  _save_noise_pattern(str(item.get("book_id", "")), noise_text)
2712
  if action == "edited":
@@ -3108,7 +3109,11 @@ def smoke_signal_tab():
3108
  interactive=False,
3109
  scale=1,
3110
  )
3111
- reviewer_name = gr.Textbox(label="Reviewer", placeholder="e.g. jamal", scale=1)
 
 
 
 
3112
  reason_code = gr.Dropdown(
3113
  label="Reason code",
3114
  choices=["","OCR_MISS","OCR_WRONG_WORD","DECORATIVE_FONT",
@@ -3146,23 +3151,26 @@ def smoke_signal_tab():
3146
 
3147
  def do_accept(idx, final, reviewer, reason, conf_ov=False):
3148
  action = "edited" if final.strip() != "" else "accepted"
3149
- fb, img, raw, info, _, _ = save_review_decision(
3150
  idx, final, action, reviewer, reason, conf_override=bool(conf_ov)
3151
  )
 
3152
  status = _review_status_html()
3153
  new_idx = idx + 1
3154
  img2, raw2, info2, _, _, font2 = get_review_item(new_idx)
3155
  return fb, status, new_idx, img2, raw2, raw2, info2, font2
3156
 
3157
  def do_reject(idx, final, reviewer, reason):
3158
- fb, img, raw, info, _, _ = save_review_decision(idx, final, "rejected", reviewer, reason)
 
3159
  status = _review_status_html()
3160
  new_idx = idx + 1
3161
  img2, raw2, info2, _, _, font2 = get_review_item(new_idx)
3162
  return fb, status, new_idx, img2, raw2, raw2, info2, font2
3163
 
3164
  def do_quarantine(idx, final, reviewer, reason):
3165
- fb, img, raw, info, _, _ = save_review_decision(idx, final, "quarantined", reviewer, reason)
 
3166
  status = _review_status_html()
3167
  new_idx = idx + 1
3168
  img2, raw2, info2, _, _, font2 = get_review_item(new_idx)
@@ -3181,10 +3189,10 @@ def smoke_signal_tab():
3181
  ocr_done.change(load_review, outputs=review_load_outputs)
3182
  pipeline_done.change(load_review, outputs=review_load_outputs)
3183
 
3184
- accept_btn.click(do_accept, inputs=[current_idx, final_text_box, reviewer_name, reason_code, conf_override], outputs=action_outputs)
3185
- edit_btn.click(do_accept, inputs=[current_idx, final_text_box, reviewer_name, reason_code, conf_override], outputs=action_outputs)
3186
- reject_btn.click(do_reject, inputs=[current_idx, final_text_box, reviewer_name, reason_code], outputs=action_outputs)
3187
- quar_btn.click(do_quarantine, inputs=[current_idx, final_text_box, reviewer_name, reason_code], outputs=action_outputs)
3188
 
3189
  def _next(idx):
3190
  new_idx = idx + 1
 
2632
  return img_path, item.get("raw_ocr",""), info, len(q_df) - len(pending), len(q_df), font_name_val
2633
 
2634
 
2635
+ def save_review_decision(idx: int, final_text: str, action: str, noise_text_input: str, reason: str, conf_override: bool = False) -> tuple:
2636
  q_df = load_queue_df()
2637
  d_df = load_decisions_df()
2638
  if q_df.empty:
 
2666
  "raw_text": raw_text,
2667
  "raw_text_original": raw_text_original,
2668
  "reason_code": reason,
2669
+ "reviewer": "smoke-signal",
2670
  "font_name": item.get("font_name", ""),
2671
  "was_correct": was_correct,
2672
  "decided_at": datetime.utcnow().isoformat() + "Z",
 
2706
 
2707
  learned_pairs = 0
2708
  if action == "rejected" and str(reason).strip() == "NON_STORY_TEXT":
2709
+ # Use pasted noise text if provided, otherwise fall back to raw OCR
2710
+ noise_text = (str(noise_text_input or "").strip() or final_text.strip() or raw_text.strip())
2711
  if noise_text:
2712
  _save_noise_pattern(str(item.get("book_id", "")), noise_text)
2713
  if action == "edited":
 
3109
  interactive=False,
3110
  scale=1,
3111
  )
3112
+ noise_input = gr.Textbox(
3113
+ label="Paste image-noise text here (then Reject → NON_STORY_TEXT to block forever)",
3114
+ placeholder="e.g. WA alle CoS lic",
3115
+ lines=2,
3116
+ )
3117
  reason_code = gr.Dropdown(
3118
  label="Reason code",
3119
  choices=["","OCR_MISS","OCR_WRONG_WORD","DECORATIVE_FONT",
 
3151
 
3152
  def do_accept(idx, final, reviewer, reason, conf_ov=False):
3153
  action = "edited" if final.strip() != "" else "accepted"
3154
+ result = save_review_decision(
3155
  idx, final, action, reviewer, reason, conf_override=bool(conf_ov)
3156
  )
3157
+ fb = result[0]
3158
  status = _review_status_html()
3159
  new_idx = idx + 1
3160
  img2, raw2, info2, _, _, font2 = get_review_item(new_idx)
3161
  return fb, status, new_idx, img2, raw2, raw2, info2, font2
3162
 
3163
  def do_reject(idx, final, reviewer, reason):
3164
+ result = save_review_decision(idx, final, "rejected", reviewer, reason)
3165
+ fb = result[0]
3166
  status = _review_status_html()
3167
  new_idx = idx + 1
3168
  img2, raw2, info2, _, _, font2 = get_review_item(new_idx)
3169
  return fb, status, new_idx, img2, raw2, raw2, info2, font2
3170
 
3171
  def do_quarantine(idx, final, reviewer, reason):
3172
+ result = save_review_decision(idx, final, "quarantined", reviewer, reason)
3173
+ fb = result[0]
3174
  status = _review_status_html()
3175
  new_idx = idx + 1
3176
  img2, raw2, info2, _, _, font2 = get_review_item(new_idx)
 
3189
  ocr_done.change(load_review, outputs=review_load_outputs)
3190
  pipeline_done.change(load_review, outputs=review_load_outputs)
3191
 
3192
+ accept_btn.click(do_accept, inputs=[current_idx, final_text_box, noise_input, reason_code, conf_override], outputs=action_outputs)
3193
+ edit_btn.click(do_accept, inputs=[current_idx, final_text_box, noise_input, reason_code, conf_override], outputs=action_outputs)
3194
+ reject_btn.click(do_reject, inputs=[current_idx, final_text_box, noise_input, reason_code], outputs=action_outputs)
3195
+ quar_btn.click(do_quarantine, inputs=[current_idx, final_text_box, noise_input, reason_code], outputs=action_outputs)
3196
 
3197
  def _next(idx):
3198
  new_idx = idx + 1