用run_in_executor运行识别代码

This commit is contained in:
zhbaor 2023-08-13 20:18:55 +08:00
parent 4a1d3978ad
commit 94eca0ebeb

View file

@ -1,6 +1,8 @@
from pepperbot.core.message.chain import MessageChain, Image, Text from pepperbot.core.message.chain import MessageChain, Image, Text
from paddleocr import PaddleOCR from paddleocr import PaddleOCR
import os import os
import asyncio
import functools
ocr = PaddleOCR(use_angle_cls=False, use_gpu=False) ocr = PaddleOCR(use_angle_cls=False, use_gpu=False)
@ -14,7 +16,11 @@ class RIICReportAnalysis:
img_path = await img_seg.download() img_path = await img_seg.download()
print(f"Image saved to {img_path}") print(f"Image saved to {img_path}")
ocr_text = ocr.ocr(img_path, cls=False) loop = asyncio.get_running_loop()
ocr_text = await loop.run_in_executor(
None, functools.partial(ocr.ocr, img_path, cls=False)
)
print(ocr_text) print(ocr_text)
os.remove(img_path) os.remove(img_path)