Spaces:
Sleeping
Sleeping
Claude commited on
Commit ·
548f2eb
1
Parent(s): b1608ed
feat: confidence override checkbox — reviewer can mark perfect pages as 100%
Browse files- smoke_signal_tab.py +17 -7
smoke_signal_tab.py
CHANGED
|
@@ -2584,7 +2584,7 @@ def get_review_item(idx: int) -> tuple:
|
|
| 2584 |
return img_path, item.get("raw_ocr",""), info, len(q_df) - len(pending), len(q_df)
|
| 2585 |
|
| 2586 |
|
| 2587 |
-
def save_review_decision(idx: int, final_text: str, action: str, reviewer: str, reason: str) -> tuple:
|
| 2588 |
q_df = load_queue_df()
|
| 2589 |
d_df = load_decisions_df()
|
| 2590 |
if q_df.empty:
|
|
@@ -2642,12 +2642,16 @@ def save_review_decision(idx: int, final_text: str, action: str, reviewer: str,
|
|
| 2642 |
except Exception:
|
| 2643 |
punct_flags_count = 0
|
| 2644 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2645 |
with open(GOLD_FILE, "a", encoding="utf-8") as f:
|
| 2646 |
f.write(json.dumps({
|
| 2647 |
**decision,
|
| 2648 |
"region_class": region_class,
|
| 2649 |
-
"confidence":
|
| 2650 |
-
"conf_class": item.get("confidence_class",""),
|
| 2651 |
"punct_score": punct_score,
|
| 2652 |
"punct_flags_count": punct_flags_count,
|
| 2653 |
}) + "\n")
|
|
@@ -3086,6 +3090,10 @@ def smoke_signal_tab():
|
|
| 3086 |
value="",
|
| 3087 |
)
|
| 3088 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3089 |
with gr.Row():
|
| 3090 |
accept_btn = gr.Button("✓ Accept", elem_classes=["ss-btn-accept"])
|
| 3091 |
edit_btn = gr.Button("✎ Save Edit", elem_classes=["ss-btn-edit"])
|
|
@@ -3109,9 +3117,11 @@ def smoke_signal_tab():
|
|
| 3109 |
img, raw, info, done, total = get_review_item(new_idx)
|
| 3110 |
return new_idx, img, raw, raw, info
|
| 3111 |
|
| 3112 |
-
def do_accept(idx, final, reviewer, reason):
|
| 3113 |
action = "edited" if final.strip() != "" else "accepted"
|
| 3114 |
-
fb, img, raw, info, _, _ = save_review_decision(
|
|
|
|
|
|
|
| 3115 |
status = _review_status_html()
|
| 3116 |
new_idx = idx + 1
|
| 3117 |
img2, raw2, info2, _, _ = get_review_item(new_idx)
|
|
@@ -3144,8 +3154,8 @@ def smoke_signal_tab():
|
|
| 3144 |
ocr_done.change(load_review, outputs=review_load_outputs)
|
| 3145 |
pipeline_done.change(load_review, outputs=review_load_outputs)
|
| 3146 |
|
| 3147 |
-
accept_btn.click(do_accept, inputs=[current_idx, final_text_box, reviewer_name, reason_code], outputs=action_outputs)
|
| 3148 |
-
edit_btn.click(do_accept, inputs=[current_idx, final_text_box, reviewer_name, reason_code], outputs=action_outputs)
|
| 3149 |
reject_btn.click(do_reject, inputs=[current_idx, final_text_box, reviewer_name, reason_code], outputs=action_outputs)
|
| 3150 |
quar_btn.click(do_quarantine, inputs=[current_idx, final_text_box, reviewer_name, reason_code], outputs=action_outputs)
|
| 3151 |
|
|
|
|
| 2584 |
return img_path, item.get("raw_ocr",""), info, len(q_df) - len(pending), len(q_df)
|
| 2585 |
|
| 2586 |
|
| 2587 |
+
def save_review_decision(idx: int, final_text: str, action: str, reviewer: str, reason: str, conf_override: bool = False) -> tuple:
|
| 2588 |
q_df = load_queue_df()
|
| 2589 |
d_df = load_decisions_df()
|
| 2590 |
if q_df.empty:
|
|
|
|
| 2642 |
except Exception:
|
| 2643 |
punct_flags_count = 0
|
| 2644 |
|
| 2645 |
+
final_confidence = 1.0 if conf_override else float(item.get("confidence", 0))
|
| 2646 |
+
if conf_override:
|
| 2647 |
+
decision["confidence_override"] = True
|
| 2648 |
+
|
| 2649 |
with open(GOLD_FILE, "a", encoding="utf-8") as f:
|
| 2650 |
f.write(json.dumps({
|
| 2651 |
**decision,
|
| 2652 |
"region_class": region_class,
|
| 2653 |
+
"confidence": final_confidence,
|
| 2654 |
+
"conf_class": "verified-100" if conf_override else item.get("confidence_class",""),
|
| 2655 |
"punct_score": punct_score,
|
| 2656 |
"punct_flags_count": punct_flags_count,
|
| 2657 |
}) + "\n")
|
|
|
|
| 3090 |
value="",
|
| 3091 |
)
|
| 3092 |
|
| 3093 |
+
conf_override = gr.Checkbox(
|
| 3094 |
+
label="Override confidence to 100% (page is perfect)",
|
| 3095 |
+
value=False,
|
| 3096 |
+
)
|
| 3097 |
with gr.Row():
|
| 3098 |
accept_btn = gr.Button("✓ Accept", elem_classes=["ss-btn-accept"])
|
| 3099 |
edit_btn = gr.Button("✎ Save Edit", elem_classes=["ss-btn-edit"])
|
|
|
|
| 3117 |
img, raw, info, done, total = get_review_item(new_idx)
|
| 3118 |
return new_idx, img, raw, raw, info
|
| 3119 |
|
| 3120 |
+
def do_accept(idx, final, reviewer, reason, conf_ov=False):
|
| 3121 |
action = "edited" if final.strip() != "" else "accepted"
|
| 3122 |
+
fb, img, raw, info, _, _ = save_review_decision(
|
| 3123 |
+
idx, final, action, reviewer, reason, conf_override=bool(conf_ov)
|
| 3124 |
+
)
|
| 3125 |
status = _review_status_html()
|
| 3126 |
new_idx = idx + 1
|
| 3127 |
img2, raw2, info2, _, _ = get_review_item(new_idx)
|
|
|
|
| 3154 |
ocr_done.change(load_review, outputs=review_load_outputs)
|
| 3155 |
pipeline_done.change(load_review, outputs=review_load_outputs)
|
| 3156 |
|
| 3157 |
+
accept_btn.click(do_accept, inputs=[current_idx, final_text_box, reviewer_name, reason_code, conf_override], outputs=action_outputs)
|
| 3158 |
+
edit_btn.click(do_accept, inputs=[current_idx, final_text_box, reviewer_name, reason_code, conf_override], outputs=action_outputs)
|
| 3159 |
reject_btn.click(do_reject, inputs=[current_idx, final_text_box, reviewer_name, reason_code], outputs=action_outputs)
|
| 3160 |
quar_btn.click(do_quarantine, inputs=[current_idx, final_text_box, reviewer_name, reason_code], outputs=action_outputs)
|
| 3161 |
|