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 import torch torch.hub.download_url_to_file('https://i.imgur.com/aqMBT0i.jpg', 'example.jpg') 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] im_show = draw_ocr(image, boxes, txts, font_path='simfang.ttf') im_show = Image.fromarray(im_show) im_show.save('result.jpg') return 'result.jpg' title = 'A Framework for Data-Driven Document Evaluation and scoring - Image to Text Extraction ' description = 'Demo for Optical character recognition(OCR)' article = "" examples = [['example.jpg','en']] 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, article=article, examples=examples, css=css, enable_queue=True ).launch(debug=True)