File tree Expand file tree Collapse file tree 7 files changed +33
-43
lines changed
Expand file tree Collapse file tree 7 files changed +33
-43
lines changed Original file line number Diff line number Diff line change 1919
2020from file_converter import ensure_pdf , OFFICE_EXTENSIONS
2121from rapid_doc .cli .common import aio_do_parse
22+ from rapid_doc .utils .pdf_image_tools import images_bytes_to_pdf_bytes
2223from rapid_doc .version import __version__
2324
2425app = 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_" )
Original file line number Diff line number Diff 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
6868core = [
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 ]
7689homepage = " https://github.com/RapidAI"
7790repository = " https://github.com/RapidAI/RapidOCR"
Original file line number Diff line number Diff line change 1- import os
2-
31from loguru import logger
42
53from .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 ,
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1212from rapid_doc .data .data_reader_writer import FileBasedDataWriter
1313from rapid_doc .utils .draw_bbox import draw_layout_bbox , draw_span_bbox , draw_line_sort_bbox
1414from rapid_doc .utils .enum_class import MakeMode
15- from rapid_doc .utils .guess_suffix_or_lang import guess_suffix_by_bytes
1615from rapid_doc .utils .pdf_image_tools import images_bytes_to_pdf_bytes
1716from 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 :
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3232
3333img_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 ]
3737ocr_results_list = []
3838for img in img_paths :
You can’t perform that action at this time.
0 commit comments