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
+2 -1
View File
@@ -177,7 +177,8 @@ def _process_wrong_question(question_id: uuid.UUID):
if "libGL" in str(exc):
msg += " 请在服务器执行: sudo bash deploy/install-ocr-deps.sh && systemctl restart grade-archive"
elif ocr_url:
msg += f" 请检查 OCR 服务是否可达: {ocr_url} (可浏览器访问 {ocr_url.rstrip('/')}/health"
if "OCR 服务" not in msg:
msg += " 诊断: bash deploy/ocr-screen.sh status && bash deploy/ocr-worker/test-ocr.sh"
wq.error_message = msg
db.commit()
return
+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()