pepperbot/apps/riic_report_analysis.py

27 lines
726 B
Python

from pepperbot.core.message.chain import MessageChain, Image, Text
from paddleocr import PaddleOCR
import os
import asyncio
import functools
ocr = PaddleOCR(use_angle_cls=False, use_gpu=False)
class RIICReportAnalysis:
async def group_message(self, chain: MessageChain):
if len(chain) != 1 or len(chain.images) != 1:
return
img_seg: Image = chain[0]
img_path = await img_seg.download()
print(f"Image saved to {img_path}")
loop = asyncio.get_running_loop()
ocr_text = await loop.run_in_executor(
None, functools.partial(ocr.ocr, img_path, cls=False)
)
print(ocr_text)
os.remove(img_path)
print(f"file removed.")