OCR 500: GPU 回退 CPU、返回详细错误、增加 test-ocr 诊断。

This commit is contained in:
dekun
2026-06-28 15:04:33 +08:00
parent edd3e80ef1
commit 0d4861fa62
5 changed files with 115 additions and 24 deletions
+11 -1
View File
@@ -130,7 +130,17 @@ def _run_remote_ocr(service_url: str, image_path: str) -> dict:
files = {"file": (Path(image_path).name, handle, "image/jpeg")}
with httpx.Client(timeout=settings.OCR_TIMEOUT_SECONDS) as client:
resp = client.post(url, files=files, headers=headers)
resp.raise_for_status()
if resp.status_code >= 400:
detail = resp.text
try:
body = resp.json()
if isinstance(body.get("detail"), str):
detail = body["detail"]
elif isinstance(body.get("detail"), list):
detail = str(body["detail"])
except Exception:
pass
raise RuntimeError(f"OCR 服务 {resp.status_code}: {detail}")
return resp.json()