Spaces:
Sleeping
Sleeping
File size: 1,296 Bytes
5b0ef18 9d8da58 5b0ef18 b673159 5b0ef18 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
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,
)
|