YashGb commited on
Commit
24aad07
Β·
1 Parent(s): fd64372

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +122 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import PIL
3
+ from PIL import Image
4
+ from PIL import ImageDraw
5
+ import gradio as gr
6
+ import torch
7
+ import easyocr
8
+
9
+
10
+ def draw_boxes(image, bounds, color='yellow', width=2):
11
+ draw = ImageDraw.Draw(image)
12
+ for bound in bounds:
13
+ p0, p1, p2, p3 = bound[0]
14
+ draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
15
+ return image
16
+
17
+ def inference(img, lang):
18
+ reader = easyocr.Reader(lang)
19
+ bounds = reader.readtext(img.name)
20
+ im = PIL.Image.open(img.name)
21
+ draw_boxes(im, bounds)
22
+ im.save('result.jpg')
23
+ return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
24
+
25
+ title = 'EasyOCR'
26
+ css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
27
+ choices = [
28
+ "abq",
29
+ "ady",
30
+ "af",
31
+ "ang",
32
+ "ar",
33
+ "as",
34
+ "ava",
35
+ "az",
36
+ "be",
37
+ "bg",
38
+ "bh",
39
+ "bho",
40
+ "bn",
41
+ "bs",
42
+ "ch_sim",
43
+ "ch_tra",
44
+ "che",
45
+ "cs",
46
+ "cy",
47
+ "da",
48
+ "dar",
49
+ "de",
50
+ "en",
51
+ "es",
52
+ "et",
53
+ "fa",
54
+ "fr",
55
+ "ga",
56
+ "gom",
57
+ "hi",
58
+ "hr",
59
+ "hu",
60
+ "id",
61
+ "inh",
62
+ "is",
63
+ "it",
64
+ "ja",
65
+ "kbd",
66
+ "kn",
67
+ "ko",
68
+ "ku",
69
+ "la",
70
+ "lbe",
71
+ "lez",
72
+ "lt",
73
+ "lv",
74
+ "mah",
75
+ "mai",
76
+ "mi",
77
+ "mn",
78
+ "mr",
79
+ "ms",
80
+ "mt",
81
+ "ne",
82
+ "new",
83
+ "nl",
84
+ "no",
85
+ "oc",
86
+ "pi",
87
+ "pl",
88
+ "pt",
89
+ "ro",
90
+ "ru",
91
+ "rs_cyrillic",
92
+ "rs_latin",
93
+ "sck",
94
+ "sk",
95
+ "sl",
96
+ "sq",
97
+ "sv",
98
+ "sw",
99
+ "ta",
100
+ "tab",
101
+ "te",
102
+ "th",
103
+ "tjk",
104
+ "tl",
105
+ "tr",
106
+ "ug",
107
+ "uk",
108
+ "ur",
109
+ "uz",
110
+ "vi"
111
+ ]
112
+ gr.Interface(
113
+ inference,
114
+ [gr.inputs.Image(type='file', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['en'], label='language')],
115
+ [gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe(headers=['text', 'confidence'])],
116
+ title=title,
117
+ description=description,
118
+ article=article,
119
+ examples=examples,
120
+ css=css,
121
+ enable_queue=True
122
+ ).launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ opencv-python-headless<4.3
2
+ Pillow
3
+ gradio
4
+ torch
5
+ easyocr