import pandas as pd import PIL from PIL import Image from PIL import ImageDraw import gradio as gr import torch import easyocr def draw_boxes(image, bounds, color='red', width=2): draw = ImageDraw.Draw(image) for bound in bounds: p0, p1, p2, p3 = bound[0] draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width) return image def inference(img): reader = easyocr.Reader(['en']) bounds = reader.readtext(img, decoder='wordbeamsearch', rotation_info =[90, 180, 270]) im = PIL.Image.open(img) draw_boxes(im, bounds) # im=im.convert('RGB') # plt.imshow(im) # plt.show() im.save('result.png') return ['result.png', pd.DataFrame(bounds).iloc[: , 1:]] title = 'Raymond Weil' examples = [['image_11.png'],['image_12.png'],['image_13.png'],['image_14.png'],['image_15.png'],['image_16.png'],['image_17.png'],['image_18.png'],['image_19.png']] css = "footer {visibility: hidden} body}, .gradio-container {background-color: white}," gr.Interface( inference, inputs=[gr.Image(label="input" ,type="filepath")], outputs=[gr.Image(type='filepath', label='Output'), gr.Dataframe(headers=['text', 'confidence'])], title=title, # description=description, examples=examples, css=css ).launch(debug=True,enable_queue=True)