Skip to content

Commit efd9587

Browse files
committed
remove magika
1 parent 37d5a10 commit efd9587

File tree

7 files changed

+33
-43
lines changed

7 files changed

+33
-43
lines changed

docker/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from file_converter import ensure_pdf, OFFICE_EXTENSIONS
2121
from rapid_doc.cli.common import aio_do_parse
22+
from rapid_doc.utils.pdf_image_tools import images_bytes_to_pdf_bytes
2223
from rapid_doc.version import __version__
2324

2425
app = FastAPI(
@@ -195,6 +196,8 @@ async def file_parse(
195196
)
196197
if file_suffix in pdf_suffixes + image_suffixes:
197198
content = await file.read()
199+
if file_suffix in image_suffixes:
200+
content = images_bytes_to_pdf_bytes(content)
198201
else:
199202
# 创建临时目录用于文档转换
200203
temp_dir = tempfile.mkdtemp(prefix="fastapi_adapter_")

pyproject.toml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies = [
3838
"shapely>=2.0.7,<3",
3939
"tokenizers>=0.13.2",
4040
"rapidocr>=3.1.0,<=3.4.2",
41-
"magika>=0.6.2,<0.7.0",
41+
# "magika>=0.6.2,<0.7.0",
4242
]
4343

4444
[project.optional-dependencies]
@@ -67,11 +67,24 @@ api = [
6767

6868
core = [
6969
"openvino>=2024.6.0",
70-
"onnxruntime-gpu",
70+
"onnxruntime-gpu<=1.23.0",
7171
"torch>=2.6.0,<3",
7272
"torchvision",
7373
]
7474

75+
npu = [
76+
"decorator",
77+
"attrs",
78+
"psutil",
79+
"cloudpickle",
80+
"ml-dtypes",
81+
"tornado",
82+
"onnxruntime-cann==1.22.0",
83+
"torch==2.5.1",
84+
"torch-npu==2.5.1",
85+
"torchvision",
86+
]
87+
7588
[project.urls]
7689
homepage = "https://github.com/RapidAI"
7790
repository = "https://github.com/RapidAI/RapidOCR"

rapid_doc/backend/pipeline/model_init.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
from loguru import logger
42

53
from .model_list import AtomicModel
@@ -124,6 +122,13 @@ def __init__(self, **kwargs):
124122
)
125123
atom_model_manager = AtomModelSingleton()
126124

125+
# 初始化layout模型
126+
self.layout_model = atom_model_manager.get_atom_model(
127+
atom_model_name=AtomicModel.Layout,
128+
device=self.device,
129+
layout_config=self.layout_config,
130+
)
131+
127132
if self.apply_formula:
128133
# 初始化公式解析模型
129134
self.formula_model = atom_model_manager.get_atom_model(
@@ -132,12 +137,6 @@ def __init__(self, **kwargs):
132137
formula_config=self.formula_config,
133138
)
134139

135-
# 初始化layout模型
136-
self.layout_model = atom_model_manager.get_atom_model(
137-
atom_model_name=AtomicModel.Layout,
138-
device=self.device,
139-
layout_config=self.layout_config,
140-
)
141140
# 初始化ocr
142141
self.ocr_model = atom_model_manager.get_atom_model(
143142
atom_model_name=AtomicModel.OCR,

rapid_doc/backend/pipeline/pipeline_analyze.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,12 @@ def batch_image_analyze(
216216
) from e
217217

218218
if str(device).startswith('npu') or str(device).startswith('cuda'):
219-
vram = get_vram(device)
220-
if vram is not None:
219+
if str(device).startswith('npu'):
220+
# onnxruntime-cann要在torch-npu之前初始化
221+
vram = int(os.getenv('MINERU_VIRTUAL_VRAM_SIZE', -1))
222+
else:
223+
vram = get_vram(device)
224+
if vram is not None and vram > 0:
221225
gpu_memory = int(os.getenv('MINERU_VIRTUAL_VRAM_SIZE', round(vram)))
222226
if gpu_memory >= 16:
223227
batch_ratio = 16

rapid_doc/cli/common.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from rapid_doc.data.data_reader_writer import FileBasedDataWriter
1313
from rapid_doc.utils.draw_bbox import draw_layout_bbox, draw_span_bbox, draw_line_sort_bbox
1414
from rapid_doc.utils.enum_class import MakeMode
15-
from rapid_doc.utils.guess_suffix_or_lang import guess_suffix_by_bytes
1615
from rapid_doc.utils.pdf_image_tools import images_bytes_to_pdf_bytes
1716
from rapid_doc.utils.pdf_page_id import get_end_page_id
1817

@@ -26,7 +25,7 @@ def read_fn(path):
2625
path = Path(path)
2726
with open(str(path), "rb") as input_file:
2827
file_bytes = input_file.read()
29-
file_suffix = guess_suffix_by_bytes(file_bytes, path)
28+
file_suffix = path.suffix[1:].lower()
3029
if file_suffix in image_suffixes:
3130
return images_bytes_to_pdf_bytes(file_bytes)
3231
elif file_suffix in pdf_suffixes:

rapid_doc/utils/guess_suffix_or_lang.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/rapid_table_v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
img_paths = [
3434
"https://raw.githubusercontent.com/RapidAI/RapidTable/refs/heads/main/tests/test_files/table.jpg",
35-
'table_05.png'
35+
# 'table_05.png'
3636
]
3737
ocr_results_list = []
3838
for img in img_paths:

0 commit comments

Comments
 (0)