Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import easyocr
|
3 |
+
import torch
|
4 |
+
import PIL
|
5 |
+
from PIL import Image
|
6 |
+
from PIL import ImageDraw
|
7 |
+
|
8 |
+
|
9 |
+
def draw_boxes(image, bounds, color='yellow', width=2):
|
10 |
+
draw = ImageDraw.Draw(image)
|
11 |
+
for bound in bounds:
|
12 |
+
p0, p1, p2, p3 = bound[0]
|
13 |
+
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
14 |
+
return image
|
15 |
+
|
16 |
+
def detect(img, lang='en'):
|
17 |
+
reader = easyocr.Reader(lang)
|
18 |
+
bounds = reader.readtext(img.name)
|
19 |
+
im = PIL.Image.open(img.name)
|
20 |
+
im_out=draw_boxes(im, bounds)
|
21 |
+
return im_out
|
22 |
+
|
23 |
+
with gr.Blocks() as robot:
|
24 |
+
im=gr.Pil()
|
25 |
+
go_btn=gr.Button()
|
26 |
+
out_im=gr.Pil()
|
27 |
+
out_txt=gr.Textbox(lines=8)
|
28 |
+
go_btn.click(detect,im,out_im)
|
29 |
+
robot.queue(concurrency_count=10).launch()
|