import os import torch print(torch.__version__) torch_ver, cuda_ver = torch.__version__.split('+') os.system('pip list') os.system(f'pip install opencv-contrib-python==4.5.5.62 --no-cache-dir') os.system('pip list') os.system(f'pip install pycocotools==2.0.0 mmdet mmcv-full==1.5.0 -f https://download.openmmlab.com/mmcv/dist/{cuda_ver}/torch1.10.0/index.html --no-cache-dir') os.system('wget -nv -c https://download.openmmlab.com/mmocr/data/wildreceipt.tar; mkdir -p data; tar -xf wildreceipt.tar --directory data; rm -f wildreceipt.tar') import datetime import gradio as gr import pandas as pd from mmocr.utils.ocr import MMOCR def inference(img): print(datetime.datetime.now(), 'start') ocr = MMOCR(det='PS_CTW', recog='SAR', kie='SDMGR') print(datetime.datetime.now(), 'start read') results = ocr.readtext(img.name, details=True, output='result.png') print(datetime.datetime.now(), results) return ['result.png', pd.DataFrame(results[0]['result']).iloc[: , 2:]] description = 'Gradio demo for MMOCR. MMOCR is an open-source toolbox based on PyTorch and mmdetection for text detection, text recognition, and the corresponding downstream tasks including key information extraction. To use it, simply upload your image or click one of the examples to load them. Read more at the links below.' article = "
MMOCR is an open-source toolbox based on PyTorch and mmdetection for text detection, text recognition, and the corresponding downstream tasks including key information extraction. | Github Repo
" gr.Interface(inference, gr.inputs.Image(type='file', label='Input'), [gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe(headers=['text', 'text_score', 'label', 'label_score'])], title='MMOCR', description=description, article=article, examples=['demo/demo_kie.jpeg', 'demo/demo_text_ocr.jpg', 'demo/demo_text_det.jpg', 'demo/demo_densetext_det.jpg'], css=".output_image, .input_image {height: 40rem !important; width: 100% !important;}", enable_queue=True ).launch(debug=True)