📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
Add whl of ocrweb
SWHL4d0fcee49771
diff --git a/.github/workflows/gen_whl_to_pypi_rapidocr_web.yml b/.github/workflows/gen_whl_to_pypi_rapidocr_web.ymlnew file mode 100644index 0000000..298c367--- /dev/null+++ b/.github/workflows/gen_whl_to_pypi_rapidocr_web.yml@@ -0,0 +1,55 @@+name: Push rapidocr_web to pypi++on:+ push:+ branches: [ main ]+ paths:+ - 'ocrweb/rapidocr_web/**'+ - 'docs/doc_whl_rapidocr_web.md'+ - 'ocrweb/setup.py'+ - '.github/workflows/gen_whl_to_pypi_rapidocr_web.yml'++jobs:+ GenerateWHL_PushPyPi:+ needs: UnitTesting+ runs-on: ubuntu-latest++ steps:+ - uses: actions/checkout@v3++ - name: Set up Python 3.7+ uses: actions/setup-python@v4+ with:+ python-version: '3.7'+ architecture: 'x64'++ - name: Set SSH Environment+ env:+ DEPLOY_KEYS: ${{ secrets.GEN_PYTHON_SDK }}+ run: |+ mkdir -p ~/.ssh/+ echo "$DEPLOY_KEYS" > ~/.ssh/id_rsa+ chmod 600 ~/.ssh/id_rsa+ chmod 700 ~/.ssh && chmod 600 ~/.ssh/*++ - name: Run setup.py+ run: |+ cd ocrweb+ pip install -r requirements.txt++ python -m pip install --upgrade pip+ python setup.py bdist_wheel ${{ github.event.head_commit.message }}+ mv dist ../++ # - name: Publish distribution 📦 to Test PyPI+ # uses: pypa/[email protected]+ # with:+ # password: ${{ secrets.TEST_PYPI_API_TOKEN }}+ # repository_url: https://test.pypi.org/legacy/+ # packages_dir: dist/++ - name: Publish distribution 📦 to PyPI+ uses: pypa/[email protected]+ with:+ password: ${{ secrets.PYPI_API_TOKEN }}+ packages_dir: dist/diff --git a/docs/doc_whl_rapidocr_web.md b/docs/doc_whl_rapidocr_web.mdindex 7a7afcb..d7f6149 100644--- a/docs/doc_whl_rapidocr_web.md+++ b/docs/doc_whl_rapidocr_web.md@@ -2,7 +2,7 @@<p><a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a><a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>- <a href="https://pypi.org/project/rapid-layout/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapid-layout"></a>+ <a href="https://pypi.org/project/rapidocr-web/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapidocr-web"></a></p>### 1. Install package by pypi.@@ -10,24 +10,7 @@$ pip install rapidocr-web```-### 2. Run by script.-- RapidLayout has the default `model_path` value, you can set the different value of `model_path` to use different models, e.g. `layout_engine = RapidLayout(model_path='layout_publaynet.onnx')`-- See details, for [README_Layout](https://github.com/RapidAI/RapidOCR/blob/f133ff008a1c60edd6e0ed882da83873aa7b113a/python/rapid_structure/docs/README_Layout.md) .-- 📌 `layout.png` source: [link](https://github.com/RapidAI/RapidOCR/blob/f133ff008a1c60edd6e0ed882da83873aa7b113a/python/rapid_structure/test_images/layout.png)--```python-import cv2-from rapid_layout import RapidLayout--layout_engine = RapidLayout()--img = cv2.imread('layout.png')--layout_res, elapse = layout_engine(img)-print(layout_res)-```--### 3. Run by command line.+### 2. Run by command line.- Usage:```bash$ rapidocr_web -h@@ -41,18 +24,44 @@ print(layout_res)```- Example:```bash+ # Web mode$ rapidocr_web -ip "0.0.0.0" -p 9003++ # API mode+ $ rapidocr_web -ip "0.0.0.0" -p 9003 -api```-### 4. Result.-- Return value.+### 3. Use.+- Web mode: Open `http://localhost:9003/` to view, enjoy it.+- API mode:```python- [- {'bbox': array([321.4160495, 91.53214898, 562.06141263, 199.85522603]), 'label': 'text'},- {'bbox': array([58.67292211, 107.29000663, 300.25448676, 199.68142]), 'label': 'table_caption'}- ]+ import ast+ import base64+ import json++ import requests+++ def get_json_format(img_path):+ with open(img_path, 'rb') as f:+ img_byte = base64.b64encode(f.read())+ img_json = json.dumps({'file': img_byte.decode('ascii')})+ return img_json+++ if __name__ == '__main__':+ url = 'http://localhost:9003/ocr'+ header = {'Content-Type': 'application/json; charset=UTF-8'}++ img_path = '1.jpg'+ img_json = get_json_format(img_path)++ response = requests.post(url, data=img_json, headers=header)+ if response.status_code == 200:+ rec_res = ast.literal_eval(response.text)+ print(rec_res)+ else:+ print(response.status_code)```-- Visualize result.- <div align="center">- <img src="https://raw.githubusercontent.com/RapidAI/RapidOCR/947c6958d30f47c7c7b016f7dc308f235acec3ee/python/rapid_structure/test_images/layout_result.jpg" width="80%" height="80%">- </div>++### See details for [RapidOCR](https://github.com/RapidAI/RapidOCR/tree/main/ocrweb).\ No newline at end of filediff --git a/ocrweb/README.md b/ocrweb/README.mdindex 93645c2..fedf62c 100755--- a/ocrweb/README.md+++ b/ocrweb/README.md@@ -1,9 +1,15 @@## RapidOCR Web Demo+<p>+ <a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>+ <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>+ <a href="https://pypi.org/project/rapidocr-web/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapidocr-web"></a>+</p>++- [RapidOCR Web Demo](#rapidocr-web-demo)- [简要说明](#简要说明)- [使用步骤](#使用步骤)- - [以API方式运行](#以api方式运行)### 简要说明@@ -11,87 +17,92 @@```textch_PP-OCRv3_det + ch_ppocr_mobile_v2.0_cls + ch_PP-OCRv3_rec```-- **运行机器配置:** `4核 AMD EPYC 7K62 48-Core Processor`-- 所有相关参数配置参见当前目录下的[`config.yaml`](./config.yaml),具体参数解释参见[Link](https://github.com/RapidAI/RapidOCR/blob/main/python/README.md#configyaml%E4%B8%AD%E5%B8%B8%E7%94%A8%E5%8F%82%E6%95%B0%E4%BB%8B%E7%BB%8D)。+- **在线demo运行机器配置:** `4核 AMD EPYC 7K62 48-Core Processor`- 网页上显示的推理时间具体解释如下:+<div align="center"><img src="../assets/ocrweb_time.jpg" width="80%" height="80%"></div>### 使用步骤-1. 安装`rapidocr_onnxruntime`+1. 安装`rapidocr_web````bashpip install rapidocr_web```-2. 安装`ocrweb`目录下的`requirements.txt`下相关包- ```shell- pip install -r requirements.txt- ```--3. 运行`main.py`- ```shell- $ python main.py- ```-4. 打开`http://0.0.0.0:9003/`即可, enjoy it!--### 以API方式运行-1. 同**以Web方式运行**中步骤1-2. 同**以Web方式运行**中步骤2-3. 运行`api.py`- ```python- $ python api.py- ```--4. 发送post请求,调用- ```python- import ast- import base64- import json-- import requests--- def get_json_format(img_path):- with open(img_path, 'rb') as f:- img_byte = base64.b64encode(f.read())- img_json = json.dumps({'file': img_byte.decode('ascii')})- return img_json--- if __name__ == '__main__':- url = 'http://localhost:9003/ocr'- header = {'Content-Type': 'application/json; charset=UTF-8'}-- img_path = '../images/1.jpg'- img_json = get_json_format(img_path)-- response = requests.post(url, data=img_json, headers=header)- if response.status_code == 200:- rec_res = ast.literal_eval(response.text)- print(rec_res)- else:- print(response.status_code)- ```--5. 输出以下结果,即为正确。- ```text- [- [[[265.0, 18.0], [472.0, 231.0], [431.0, 271.0], [223.0, 59.0]], '香港深圳抽血', 0.8021483932222638],- [[[388.0, 15.0], [636.0, 257.0], [587.0, 307.0], [339.0, 65.0]], '专业查性别', 0.7488822937011719],- [[[215.0, 84.0], [509.0, 413.0], [453.0, 463.0], [159.0, 134.0]], '专业鉴定B超单', 0.8711239919066429],- [[[128.0, 135.0], [430.0, 478.0], [366.0, 534.0], [64.0, 192.0]], 'b超仪器查性别', 0.8705329671502113],- [[[58.0, 189.0], [268.0, 450.0], [209.0, 498.0], [0.0, 236.0]], '加微信eee', 0.8492027946880886],- [[[493.0, 261.0], [617.0, 384.0], [577.0, 423.0], [454.0, 300.0]], '可邮寄', 0.7494295984506607]- ]- ```- - 输出结果说明:- - 如果图像中存在文字,则会输出`list`类型,具体格式介绍如下:- ```text- [- # 坐标为左上角 → 右上角 → 右下角 → 左下角- [[[left, top], [right, top], [right, bottom], [left, bottom]], 识别文本, 置信度]- ]- ```- - 如果没有检测到文字,则会输出空列表(`[]`)。-6. **!!说明:OCR的输出结果为最原始结果,大家可按需进一步扩展。**+2. 运行+ - 用法:+ ```bash+ $ rapidocr_web -h+ usage: rapidocr_web [-h] [-ip IP] [-p PORT] [-api]++ optional arguments:+ -h, --help show this help message and exit+ -ip IP, --ip IP IP Address+ -p PORT, --port PORT IP port+ -api, --is_api Whether to use the api format.+ ```+ - 示例:+ ```bash+ # 界面模式+ $ rapidocr_web -ip "0.0.0.0" -p 9003++ # API调用模式+ $ rapidocr_web -ip "0.0.0.0" -p 9003 -api+ ```++3. 使用+ - 界面模式:浏览器打开`http://localhost:9003/`,enjoy it.+ - API模式:+ ```python+ import ast+ import base64+ import json++ import requests+++ def get_json_format(img_path):+ with open(img_path, 'rb') as f:+ img_byte = base64.b64encode(f.read())+ img_json = json.dumps({'file': img_byte.decode('ascii')})+ return img_json+++ if __name__ == '__main__':+ url = 'http://localhost:9003/ocr'+ header = {'Content-Type': 'application/json; charset=UTF-8'}++ img_path = '../images/1.jpg'+ img_json = get_json_format(img_path)++ response = requests.post(url, data=img_json, headers=header)+ if response.status_code == 200:+ rec_res = ast.literal_eval(response.text)+ print(rec_res)+ else:+ print(response.status_code)+ ```++4. API输出+ - 示例结果:+ ```text+ [+ [[[265.0, 18.0], [472.0, 231.0], [431.0, 271.0], [223.0, 59.0]], '香港深圳抽血', 0.8021483932222638],+ [[[388.0, 15.0], [636.0, 257.0], [587.0, 307.0], [339.0, 65.0]], '专业查性别', 0.7488822937011719],+ [[[215.0, 84.0], [509.0, 413.0], [453.0, 463.0], [159.0, 134.0]], '专业鉴定B超单', 0.8711239919066429],+ [[[128.0, 135.0], [430.0, 478.0], [366.0, 534.0], [64.0, 192.0]], 'b超仪器查性别', 0.8705329671502113],+ [[[58.0, 189.0], [268.0, 450.0], [209.0, 498.0], [0.0, 236.0]], '加微信eee', 0.8492027946880886],+ [[[493.0, 261.0], [617.0, 384.0], [577.0, 423.0], [454.0, 300.0]], '可邮寄', 0.7494295984506607]+ ]+ ```+ - 输出结果说明,如果图像中存在文字,则会输出`List`类型,具体格式介绍如下:+ ```text+ [+ # 坐标为左上角 → 右上角 → 右下角 → 左下角+ [[[left, top], [right, top], [right, bottom], [left, bottom]], 识别文本, 置信度]+ ]+ ```+ - 如果没有检测到文字,则会输出空列表(`[]`)。++5. **!!说明:OCR的输出结果为最原始结果,大家可按需进一步扩展。**diff --git a/ocrweb/rapidocr_web/ocrweb.py b/ocrweb/rapidocr_web/ocrweb.pyindex 614caa8..de45234 100644--- a/ocrweb/rapidocr_web/ocrweb.py+++ b/ocrweb/rapidocr_web/ocrweb.py@@ -6,7 +6,10 @@ from pathlib import Pathfrom wsgiref.simple_server import make_serverfrom flask import Flask, render_template, request-from .task import OCRWebUtils+try:+ from .task import OCRWebUtils+except:+ from task import OCRWebUtilsroot_dir = Path(__file__).resolve().parentdiff --git a/ocrweb/setup.py b/ocrweb/setup.pyindex 90ef766..deab185 100644--- a/ocrweb/setup.py+++ b/ocrweb/setup.py@@ -67,6 +67,7 @@ setuptools.setup(author="SWHL",author_email="[email protected]",url="https://github.com/RapidAI/RapidOCR",+ download_url='https://github.com/RapidAI/RapidOCR.git',license='Apache-2.0',include_package_data=True,install_requires=["Pillow>=1.2.1", "requests",