File size: 728 Bytes
0445b72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import easyocr
import torch
import PIL
from PIL import Image
from PIL import ImageDraw


def draw_boxes(image, bounds, color='yellow', 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 detect(img, lang='en'):
    reader = easyocr.Reader(lang)
    bounds = reader.readtext(img.name)
    im = PIL.Image.open(img.name)
    im_out=draw_boxes(im, bounds)
    return im_out

with gr.Blocks() as robot:
    im=gr.Pil()
    go_btn=gr.Button()
    out_im=gr.Pil()
    out_txt=gr.Textbox(lines=8)
    go_btn.click(detect,im,out_im)
robot.queue(concurrency_count=10).launch()