ocr_with_fastapi / ofa_ocr.py
rogerxavier's picture
Update ofa_ocr.py
9d8da58 verified
raw
history blame
1.3 kB
import os
os.system('cd ezocr;'
'pip install .; cd ..')
import gradio as gr
import pandas as pd
from PIL import ImageDraw
from easyocrlite import ReaderLite
from PIL import Image
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.outputs import OutputKeys
# step 1. orc detection to find boxes
reader = ReaderLite(gpu=True)
# step 2. recognize ocr result according to ocr detection results
ocr_recognize = pipeline(Tasks.ocr_recognition,
model='damo/ofa_ocr-recognition_general_base_zh', model_revision='v1.0.0')
def get_images(img: str, reader: ReaderLite, **kwargs):
results = reader.process(img, **kwargs)
return results
def ofa_ocr_gr():
def ocr_api(img):
results = get_images(img, reader, max_size=4000, text_confidence=0.7, text_threshold=0.4,
link_threshold=0.4, slope_ths=0., add_margin=0.04)
box_list, image_list = zip(*results)
return box_list ##返回box_list 方便作为api结果
return ocr_api#返回子函数最后才能获取box ,至于ocr_demo这个gradio可有可无
if __name__ == "__main__":
ocr_demo = ofa_ocr_gr()
ocr_demo.launch(
share=True,
enable_queue=True,
)