ocr: 用腾讯云 QuestionSplitOCR 替换 TextIn 擦除
- 新增 backend/tencent_ocr.py(TC3 签名 + 结果解析,零依赖)
- create_paper_from_image 改为 腾讯 -> 本机 OCR+正则 -> 演示题库 三级兜底
- 删掉 TextIn 客户端、擦除页路由 /api/papers/{pid}/clean 与相关测试
- 新增 tests/test_tencent_ocr.py(13 例,全打桩);单测 114 例、冒烟 39 项全过
This commit is contained in:
@@ -46,7 +46,6 @@ MAX_BODY = 16 * 1024 * 1024 # 与 Caddy 的 request_body max_size 对
|
||||
QUERY_TOKEN_PATHS = (
|
||||
re.compile(r"^/api/export/csv$"),
|
||||
re.compile(r"^/api/print/weekly$"),
|
||||
re.compile(r"^/api/papers/[^/]+/clean$"),
|
||||
)
|
||||
|
||||
|
||||
@@ -283,20 +282,6 @@ def post_paper_ocr(ctx: Ctx, **kw):
|
||||
fallback_demo=bool(ctx.body.get("fallback_demo", True)))
|
||||
|
||||
|
||||
@route("GET", r"/api/papers/(?P<pid>[^/]+)/clean", auth="parent")
|
||||
def paper_clean(ctx: Ctx, pid: str, **kw):
|
||||
"""擦除手写后的干净页(token 可放 query,方便新标签页直接打开)。"""
|
||||
row = ctx.conn.execute("SELECT child_id, clean_path FROM papers WHERE id=?", (pid,)).fetchone()
|
||||
if not row or not row["clean_path"]:
|
||||
raise ApiError(404, "NO_CLEAN", "这张卷子没有擦除后的干净页")
|
||||
svc.get_child(ctx.conn, ctx.gid, row["child_id"])
|
||||
fp = ROOT / row["clean_path"]
|
||||
if not fp.exists():
|
||||
raise ApiError(404, "NO_CLEAN", "干净页文件不在了")
|
||||
# TextIn 擦除出来的是 .jpg,别一律当 png 发
|
||||
return ("png" if fp.suffix.lower() == ".png" else "jpg", fp.read_bytes())
|
||||
|
||||
|
||||
@route("GET", r"/api/papers/(?P<pid>[^/]+)", auth="parent")
|
||||
def get_paper(ctx: Ctx, pid: str, **kw):
|
||||
return svc.get_paper(ctx.conn, ctx.gid, ctx.q("child_id"), pid)
|
||||
|
||||
Reference in New Issue
Block a user