"ppocr/git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "a40f64a70b8d290b74557a41d869c0f9ce4959d5"
Commit c88b297c authored by zhougaofeng's avatar zhougaofeng
Browse files

Update cut_image.py

parent b0aeaeaa
...@@ -8,15 +8,12 @@ from magic_pdf.libs.ocr_content_type import ContentType ...@@ -8,15 +8,12 @@ from magic_pdf.libs.ocr_content_type import ContentType
from magic_pdf.libs.pdf_image_tools import cut_image from magic_pdf.libs.pdf_image_tools import cut_image
from multiprocessing import Pool from multiprocessing import Pool
# vllm:
from magic_pdf.dict2md.ocr_vllm_client import PredictClient,compress_image
# 普通 非vllm
# from magic_pdf.dict2md.ocr_client import PredictClient,compress_image
text = '解析图片内容,直接返回一段带有逻辑性的中文书面语描述,要求表达精准,不脱离图片中的实际内容,不要带换行,文中所有的名词不要用指代词' text = '解析图片内容,直接返回一段带有逻辑性的中文书面语描述,要求表达精准,不脱离图片中的实际内容,不要带换行,文中所有的名词不要用指代词'
client = None client = None
def ocr_image(image_path):
def ocr_image(image_path,compress_image):
start = time.time() start = time.time()
compress_image(image_path) compress_image(image_path)
txt = os.getpid() txt = os.getpid()
...@@ -31,13 +28,19 @@ def ocr_cut_image_and_table(ocr_status,config_path,local_image_dir,spans, page, ...@@ -31,13 +28,19 @@ def ocr_cut_image_and_table(ocr_status,config_path,local_image_dir,spans, page,
def return_path(type): def return_path(type):
return join_path(pdf_bytes_md5, type) return join_path(pdf_bytes_md5, type)
pool = Pool(4)
global client global client
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(config_path) config.read(config_path)
vllm_able = config.get('vllm', 'vllm_able')
if vllm_able:
from magic_pdf.dict2md.ocr_vllm_client import PredictClient, compress_image
else:
from magic_pdf.dict2md.ocr_client import PredictClient,compress_image
url = config.get('server', 'ocr_server') url = config.get('server', 'ocr_server')
workers = int(config.get('server', 'ocr_workers'))
client = PredictClient(url) client = PredictClient(url)
pool = Pool(workers)
if not ocr_status: if not ocr_status:
logger.warning(f'Health check failed. The server at "{url}" is not responding as expected.') logger.warning(f'Health check failed. The server at "{url}" is not responding as expected.')
logger.info(f'Qwen ocr解析服务无法正常运行,暂不使用qwen解析表格服务') logger.info(f'Qwen ocr解析服务无法正常运行,暂不使用qwen解析表格服务')
...@@ -57,7 +60,7 @@ def ocr_cut_image_and_table(ocr_status,config_path,local_image_dir,spans, page, ...@@ -57,7 +60,7 @@ def ocr_cut_image_and_table(ocr_status,config_path,local_image_dir,spans, page,
image_path = join_path(local_image_dir, image_path) image_path = join_path(local_image_dir, image_path)
if ocr_status: if ocr_status:
txt = pool.apply_async(ocr_image, args=(image_path,)).get() txt = pool.apply_async(ocr_image, args=(image_path,compress_image)).get()
span['image_path'] = str(txt) span['image_path'] = str(txt)
else: else:
span['image_path'] = f"----------------图片路径为({image_path}),请检查qwen ocr服务,重新运行文件解析------------------- \n" span['image_path'] = f"----------------图片路径为({image_path}),请检查qwen ocr服务,重新运行文件解析------------------- \n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment