OCR 500: GPU 回退 CPU、返回详细错误、增加 test-ocr 诊断。
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user