Spaces:
Runtime error
Runtime error
File size: 1,695 Bytes
d657d5c 4f6287b c730fe9 ebb9438 4e8b346 ebb9438 389b598 ebb9438 02fe200 389b598 ebb9438 389b598 ceadf72 |
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 |
import os
os.system('pip install paddlepaddle')
os.system('pip install paddleocr')
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
import gradio as gr
ocr = PaddleOCR(use_angle_cls=True, lang='en',use_gpu=False)
torch.hub.download_url_to_file('https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.3/doc/imgs_en/254.jpg', 'receipt.jpg')
def inference(img):
img_path = img.name
result = ocr.ocr(img_path, cls=True)
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores,
font_path='simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
return 'result.jpg'
title = 'PaddleOCR'
description = 'Gradio demo for PaddleOCR. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below.'
article = "<p style='text-align: center'><a href='https://www.paddlepaddle.org.cn/hub/scene/ocr'>Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)</a> | <a href='https://github.com/PaddlePaddle/PaddleOCR'>Github Repo</a></p>"
examples = [['receipt.jpg']]
gr.Interface(
inference,
gr.inputs.Image(type='file', label='Input'),
gr.outputs.Image(type='file', label='Output'),
title=title,
description=description,
article=article,
examples=examples
).launch(debug=True) |