File size: 1,311 Bytes
2d5ea50 d362067 2d5ea50 b5ba74d 5c712db 3703d58 d362067 2d5ea50 50513ee 5c712db 2d5ea50 5c712db 2d5ea50 50513ee |
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 |
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image, ImageFont
import gradio as gr
import torch
def inference(img, lang):
ocr = PaddleOCR(use_angle_cls=True, lang=lang,use_gpu=False)
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]
font = ImageFont.truetype("simfang.ttf", 18)
im_show = draw_ocr(image, boxes, txts, scores,
font_path=font)
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
return 'result.jpg'
title = 'OCR'
description = 'OCR demo (supports Chinese, English, French, German, Korean and Japanese). Simply upload your image and choose a language from the dropdown menu.'
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
gr.Interface(
inference,
[gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices=['ch', 'en', 'fr', 'german', 'korean', 'japan'], type="value", default='en', label='language')],
gr.outputs.Image(type='file', label='Output'),
title=title,
description=description,
css=css,
enable_queue=True
).launch(debug=True)
|