Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,95 @@ import PIL
|
|
6 |
from PIL import Image
|
7 |
from PIL import ImageDraw
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def draw_boxes(image, bounds, color='blue', width=1):
|
11 |
draw = ImageDraw.Draw(image)
|
@@ -14,7 +103,7 @@ def draw_boxes(image, bounds, color='blue', width=1):
|
|
14 |
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
15 |
return image
|
16 |
|
17 |
-
def detect(img, lang=
|
18 |
reader = easyocr.Reader(lang)
|
19 |
bounds = reader.readtext(img)
|
20 |
im = PIL.Image.open(img)
|
@@ -27,6 +116,6 @@ with gr.Blocks() as robot:
|
|
27 |
out_im=gr.Image()
|
28 |
with gr.Row():
|
29 |
out_txt=gr.Textbox(lines=8)
|
30 |
-
data_f=gr.Dataframe(
|
31 |
go_btn.click(detect,im,[out_im,out_txt,data_f])
|
32 |
robot.queue(concurrency_count=10).launch()
|
|
|
6 |
from PIL import Image
|
7 |
from PIL import ImageDraw
|
8 |
|
9 |
+
ocr_lang=[
|
10 |
+
'abq',
|
11 |
+
'ady',
|
12 |
+
'af',
|
13 |
+
'ang',
|
14 |
+
'ar',
|
15 |
+
'as',
|
16 |
+
'ava',
|
17 |
+
'az',
|
18 |
+
'be',
|
19 |
+
'bg',
|
20 |
+
'bh',
|
21 |
+
'bho',
|
22 |
+
'bn',
|
23 |
+
'bs',
|
24 |
+
'ch_sim',
|
25 |
+
'ch_tra',
|
26 |
+
'che',
|
27 |
+
'cs',
|
28 |
+
'cy',
|
29 |
+
'da',
|
30 |
+
'dar',
|
31 |
+
'de',
|
32 |
+
'en',
|
33 |
+
'es',
|
34 |
+
'et',
|
35 |
+
'fa',
|
36 |
+
'fr',
|
37 |
+
'ga',
|
38 |
+
'gom',
|
39 |
+
'hi',
|
40 |
+
'hr',
|
41 |
+
'hu',
|
42 |
+
'id',
|
43 |
+
'inh',
|
44 |
+
'is',
|
45 |
+
'it',
|
46 |
+
'ja',
|
47 |
+
'kbd',
|
48 |
+
'kn',
|
49 |
+
'ko',
|
50 |
+
'ku',
|
51 |
+
'la',
|
52 |
+
'lbe',
|
53 |
+
'lez',
|
54 |
+
'lt',
|
55 |
+
'lv',
|
56 |
+
'mah',
|
57 |
+
'mai',
|
58 |
+
'mi',
|
59 |
+
'mn',
|
60 |
+
'mr',
|
61 |
+
'ms',
|
62 |
+
'mt',
|
63 |
+
'ne',
|
64 |
+
'new',
|
65 |
+
'nl',
|
66 |
+
'no',
|
67 |
+
'oc',
|
68 |
+
'pi',
|
69 |
+
'pl',
|
70 |
+
'pt',
|
71 |
+
'ro',
|
72 |
+
'ru',
|
73 |
+
'rs_cyrillic',
|
74 |
+
'rs_latin',
|
75 |
+
'sck',
|
76 |
+
'sk',
|
77 |
+
'sl',
|
78 |
+
'sq',
|
79 |
+
'sv',
|
80 |
+
'sw',
|
81 |
+
'ta',
|
82 |
+
'tab',
|
83 |
+
'te',
|
84 |
+
'th',
|
85 |
+
'tjk',
|
86 |
+
'tl',
|
87 |
+
'tr',
|
88 |
+
'ug',
|
89 |
+
'uk',
|
90 |
+
'ur',
|
91 |
+
'uz',
|
92 |
+
'vi',
|
93 |
+
|
94 |
+
]
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
|
99 |
def draw_boxes(image, bounds, color='blue', width=1):
|
100 |
draw = ImageDraw.Draw(image)
|
|
|
103 |
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
104 |
return image
|
105 |
|
106 |
+
def detect(img, lang=ocr_lang):
|
107 |
reader = easyocr.Reader(lang)
|
108 |
bounds = reader.readtext(img)
|
109 |
im = PIL.Image.open(img)
|
|
|
116 |
out_im=gr.Image()
|
117 |
with gr.Row():
|
118 |
out_txt=gr.Textbox(lines=8)
|
119 |
+
data_f=gr.Dataframe()
|
120 |
go_btn.click(detect,im,[out_im,out_txt,data_f])
|
121 |
robot.queue(concurrency_count=10).launch()
|