惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
博客园_首页
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
The Cloudflare Blog
罗磊的独立博客
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog
Last Week in AI
Last Week in AI
J
Java Code Geeks
MyScale Blog
MyScale Blog
G
Google Developers Blog
U
Unit 42
Y
Y Combinator Blog
P
Proofpoint News Feed
Vercel News
Vercel News

博客园 - 荣锋亮

pg-boss 基于pg 的node 队列job 服务 Omnigres 基于pg的开发平台 zerofs 支持native kernel client multigres pg 版的Vitess drizzle-duckdb duckdb drizzle orm client dumbodb 面向文档db 的版本管理db doltlite sqlite 的版本控制 doltgresql pg 的dolt 服务 TokenHub 基于golang 的llm proxy 服务 duckgres PostHog 开源的通过pg协议暴露duckdb服务能力 jenkins 2.568.1 publish over ssh java.lang.NoSuchMethodError: 'java.lang.Object jenkins.plugins.publish_over_ssh.BapSshHostConfiguration 问题 scriptc vercel 开源的ts 转native 编译器 itty-router 轻量的microrouter drizzle-proxy 格式简单说明 drizzle-proxy 简单说明 duckdb iceberg rest catalog连接的一个问题 supabase wrappers pg 扩展服务 ice 运行简单说明 pgnats pg 的nats 扩展 ice 轻量iceberg rest catalog 服务 zerofs v2.1.0 支持无缝的ha 以及恢复了 liteparse 的可视化引用 VaultS3 与zerofs 集成测试 VaultS3 一个轻量的s3 兼容服务 liteparse-server liteparse rest&grpc服务 smoothdb 兼容postgrest的服务 fluxbase 基于golang 开发的兼容supabase的服务 pg_durable 微软开源的基于pg 的持久运行扩展 liteparse ocr api 规范 apache/fluss 面向实时分析以及ai 的流存储引擎
基于litserve 以及RapidOCR扩展一个liteparse ocr 服务
荣锋亮 · 2026-07-21 · via 博客园 - 荣锋亮

liteparse 是一个很不错的pdf 解析框架,提供了node 以及python sdk,内部同时提供了一个ocr 扩展接口,可以自己扩展,以下是基于

litserve 以及RapidOCR 的实现

RapidOCR 简单说明

RapidOCR 内部实际就是PaddleOCR,RapidOCR 做了一些包装优化

参考代码

  • 依赖
[project]
name = "rapidocr-liteparse"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12,<=3.14"
dependencies = [
    "litserve>=0.2.17",
    "rapidocr>=3.9.1",
    "pillow>=12.1.1",
    "onnxruntime>=1.23.2",
    "python-multipart>=0.0.22",
    "uvicorn>=0.41.0",
]

  • server.py
import litserve as ls
import io
from PIL import Image
from rapidocr import  RapidOCR
from pydantic import BaseModel
from typing import Any

class OcrResponse(BaseModel):
    results: list[Any]

class OcrAPI(ls.LitAPI):
    def setup(self, device):
        self.engine = RapidOCR()
    def normalize_language(self, lang):
        # 模仿你示例中的规范化逻辑
        lang_map = {"en": "en", "english": "en", "zh": "zh", "chinese": "zh"}
        return lang_map.get(lang.lower(), "zh")  # 默认中文

    def decode_request(self, request):
        # 1. 获取上传的文件(字段名 "file")
        file_obj = request["file"]
        contents = file_obj.file.read()
        pil_image = Image.open(io.BytesIO(contents)).convert("RGB")

        # 2. 获取语言参数(字段名 "language",默认 "en")
        lang = request.get("language", "zh")
        lang = self.normalize_language(lang)

        # 返回一个元组,供 predict 使用
        return pil_image, lang

    def predict(self, inputs):
        image, lang = inputs
        import time
        start_time = time.time()
        print("starting", time.time())
        result = self.engine(image)
        print(f"Performing OCR with language: {lang}")
        end_time = time.time()
        print("ending", end_time)
        print(f"OCR processing time: {end_time - start_time} seconds")
        final_result = []
        boxes = [] if result.boxes is None else result.boxes
        txts = [] if result.txts is None else result.txts
        scores = [] if result.scores is None else result.scores
        for box, text, score in zip(
                boxes,
                txts,
                scores,
            ):
            xs = [p[0] for p in box]
            ys = [p[1] for p in box]
            xmin = min(xs)
            ymin = min(ys)
            xmax = max(xs)
            ymax = max(ys)
            bbox = [float(xmin), float(ymin), float(xmax), float(ymax)]
            confidence = float(score)
            item = {"text": text, "bbox": bbox, "confidence": confidence}
            final_result.append(item)
        return OcrResponse(results=final_result)

if __name__ == "__main__":
    api = OcrAPI()
    server = ls.LitServer(api, api_path="/ocr",workers_per_device=1)  # 自定义端点路径
    server.run(port=8000)

说明

简单示例代码我已经放github 了litparse-rapidocr,可以直接使用

参考资料

https://github.com/run-llama/liteparse/blob/main/docs/src/content/docs/liteparse/guides/ocr.md

https://github.com/run-llama/liteparse/blob/main/OCR_API_SPEC.md

https://github.com/rapidai/rapidocr

https://github.com/lightning-ai/litserve

https://github.com/rongfengliang/litparse-rapidocr