fix(ocr-pipeline): IndentationError in auto-mode deskew block
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 26s
CI / test-go-edu-search (push) Successful in 26s
CI / test-python-klausur (push) Failing after 1m49s
CI / test-python-agent-core (push) Successful in 17s
CI / test-nodejs-website (push) Successful in 17s

The try/except block for the deskew step had 4 extra spaces of
indentation from a previous edit. Python rejected the file with
IndentationError at startup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-03 13:21:49 +01:00
parent 50e1c964ee
commit 7eb03ca8d1

View File

@@ -2153,69 +2153,69 @@ async def run_auto(session_id: str, req: RunAutoRequest, request: Request):
# ----------------------------------------------------------------- # -----------------------------------------------------------------
if req.from_step <= 1: if req.from_step <= 1:
yield await _auto_sse_event("deskew", "start", {}) yield await _auto_sse_event("deskew", "start", {})
try:
t0 = time.time()
orig_bgr = cached.get("original_bgr")
if orig_bgr is None:
raise ValueError("Original image not loaded")
# Method 1: Hough lines
try: try:
t0 = time.time() deskewed_hough, angle_hough = deskew_image(orig_bgr.copy())
orig_bgr = cached.get("original_bgr") except Exception:
if orig_bgr is None: deskewed_hough, angle_hough = orig_bgr, 0.0
raise ValueError("Original image not loaded")
# Method 1: Hough lines # Method 2: Word alignment
try: success_enc, png_orig = cv2.imencode(".png", orig_bgr)
deskewed_hough, angle_hough = deskew_image(orig_bgr.copy()) orig_bytes = png_orig.tobytes() if success_enc else b""
except Exception: try:
deskewed_hough, angle_hough = orig_bgr, 0.0 deskewed_wa_bytes, angle_wa = deskew_image_by_word_alignment(orig_bytes)
except Exception:
deskewed_wa_bytes, angle_wa = orig_bytes, 0.0
# Method 2: Word alignment # Pick best method
success_enc, png_orig = cv2.imencode(".png", orig_bgr) if abs(angle_wa) >= abs(angle_hough) or abs(angle_hough) < 0.1:
orig_bytes = png_orig.tobytes() if success_enc else b"" method_used = "word_alignment"
try: angle_applied = angle_wa
deskewed_wa_bytes, angle_wa = deskew_image_by_word_alignment(orig_bytes) wa_arr = np.frombuffer(deskewed_wa_bytes, dtype=np.uint8)
except Exception: deskewed_bgr = cv2.imdecode(wa_arr, cv2.IMREAD_COLOR)
deskewed_wa_bytes, angle_wa = orig_bytes, 0.0 if deskewed_bgr is None:
deskewed_bgr = deskewed_hough
# Pick best method
if abs(angle_wa) >= abs(angle_hough) or abs(angle_hough) < 0.1:
method_used = "word_alignment"
angle_applied = angle_wa
wa_arr = np.frombuffer(deskewed_wa_bytes, dtype=np.uint8)
deskewed_bgr = cv2.imdecode(wa_arr, cv2.IMREAD_COLOR)
if deskewed_bgr is None:
deskewed_bgr = deskewed_hough
method_used = "hough"
angle_applied = angle_hough
else:
method_used = "hough" method_used = "hough"
angle_applied = angle_hough angle_applied = angle_hough
deskewed_bgr = deskewed_hough else:
method_used = "hough"
angle_applied = angle_hough
deskewed_bgr = deskewed_hough
success, png_buf = cv2.imencode(".png", deskewed_bgr) success, png_buf = cv2.imencode(".png", deskewed_bgr)
deskewed_png = png_buf.tobytes() if success else b"" deskewed_png = png_buf.tobytes() if success else b""
deskew_result = { deskew_result = {
"method_used": method_used, "method_used": method_used,
"rotation_degrees": round(float(angle_applied), 3), "rotation_degrees": round(float(angle_applied), 3),
"duration_seconds": round(time.time() - t0, 2), "duration_seconds": round(time.time() - t0, 2),
} }
cached["deskewed_bgr"] = deskewed_bgr cached["deskewed_bgr"] = deskewed_bgr
cached["deskew_result"] = deskew_result cached["deskew_result"] = deskew_result
await update_session_db( await update_session_db(
session_id, session_id,
deskewed_png=deskewed_png, deskewed_png=deskewed_png,
deskew_result=deskew_result, deskew_result=deskew_result,
auto_rotation_degrees=float(angle_applied), auto_rotation_degrees=float(angle_applied),
current_step=2, current_step=2,
) )
session = await get_session_db(session_id) session = await get_session_db(session_id)
steps_run.append("deskew") steps_run.append("deskew")
yield await _auto_sse_event("deskew", "done", deskew_result) yield await _auto_sse_event("deskew", "done", deskew_result)
except Exception as e: except Exception as e:
logger.error(f"Auto-mode deskew failed for {session_id}: {e}") logger.error(f"Auto-mode deskew failed for {session_id}: {e}")
error_step = "deskew" error_step = "deskew"
yield await _auto_sse_event("deskew", "error", {"message": str(e)}) yield await _auto_sse_event("deskew", "error", {"message": str(e)})
yield await _auto_sse_event("complete", "error", {"error_step": error_step}) yield await _auto_sse_event("complete", "error", {"error_step": error_step})
return return
else: else:
steps_skipped.append("deskew") steps_skipped.append("deskew")
yield await _auto_sse_event("deskew", "skipped", {"reason": "from_step > 1"}) yield await _auto_sse_event("deskew", "skipped", {"reason": "from_step > 1"})