tomofi commited on
Commit
6e8537f
·
1 Parent(s): 49d9ac8

Add application file

Browse files
Files changed (2) hide show
  1. app.py +131 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from PIL import Image
3
+ from PIL import ImageDraw
4
+ import gradio as gr
5
+ import torch
6
+ import easyocr
7
+
8
+ torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/english.png', 'english.png')
9
+ torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/thai.jpg', 'thai.jpg')
10
+ torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/french.jpg', 'french.jpg')
11
+ torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/chinese.jpg', 'chinese.jpg')
12
+ torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/japanese.jpg', 'japanese.jpg')
13
+ torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/korean.png', 'korean.png')
14
+ torch.hub.download_url_to_file('https://i.imgur.com/mwQFd7G.jpeg', 'Hindi.jpeg')
15
+
16
+ def draw_boxes(image, bounds, color='yellow', width=2):
17
+ draw = ImageDraw.Draw(image)
18
+ for bound in bounds:
19
+ p0, p1, p2, p3 = bound[0]
20
+ draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
21
+ return image
22
+
23
+ def inference(img, lang):
24
+ reader = easyocr.Reader(lang)
25
+ bounds = reader.readtext(img.name)
26
+ im = PIL.Image.open(img.name)
27
+ draw_boxes(im, bounds)
28
+ im.save('result.jpg')
29
+ return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
30
+
31
+ title = 'EasyOCR'
32
+ description = 'Gradio demo for EasyOCR. EasyOCR demo supports 80+ languages.To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to load them. Read more at the links below.'
33
+ article = "<p style='text-align: center'><a href='https://www.jaided.ai/easyocr/'>Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.</a> | <a href='https://github.com/JaidedAI/EasyOCR'>Github Repo</a></p>"
34
+ examples = [['english.png',['en']],['thai.jpg',['th']],['french.jpg',['fr', 'en']],['chinese.jpg',['ch_sim', 'en']],['japanese.jpg',['ja', 'en']],['korean.png',['ko', 'en']],['Hindi.jpeg',['hi', 'en']]]
35
+ css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
36
+ choices = [
37
+ "abq",
38
+ "ady",
39
+ "af",
40
+ "ang",
41
+ "ar",
42
+ "as",
43
+ "ava",
44
+ "az",
45
+ "be",
46
+ "bg",
47
+ "bh",
48
+ "bho",
49
+ "bn",
50
+ "bs",
51
+ "ch_sim",
52
+ "ch_tra",
53
+ "che",
54
+ "cs",
55
+ "cy",
56
+ "da",
57
+ "dar",
58
+ "de",
59
+ "en",
60
+ "es",
61
+ "et",
62
+ "fa",
63
+ "fr",
64
+ "ga",
65
+ "gom",
66
+ "hi",
67
+ "hr",
68
+ "hu",
69
+ "id",
70
+ "inh",
71
+ "is",
72
+ "it",
73
+ "ja",
74
+ "kbd",
75
+ "kn",
76
+ "ko",
77
+ "ku",
78
+ "la",
79
+ "lbe",
80
+ "lez",
81
+ "lt",
82
+ "lv",
83
+ "mah",
84
+ "mai",
85
+ "mi",
86
+ "mn",
87
+ "mr",
88
+ "ms",
89
+ "mt",
90
+ "ne",
91
+ "new",
92
+ "nl",
93
+ "no",
94
+ "oc",
95
+ "pi",
96
+ "pl",
97
+ "pt",
98
+ "ro",
99
+ "ru",
100
+ "rs_cyrillic",
101
+ "rs_latin",
102
+ "sck",
103
+ "sk",
104
+ "sl",
105
+ "sq",
106
+ "sv",
107
+ "sw",
108
+ "ta",
109
+ "tab",
110
+ "te",
111
+ "th",
112
+ "tjk",
113
+ "tl",
114
+ "tr",
115
+ "ug",
116
+ "uk",
117
+ "ur",
118
+ "uz",
119
+ "vi"
120
+ ]
121
+ gr.Interface(
122
+ inference,
123
+ [gr.inputs.Image(type='file', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['en'], label='language')],
124
+ [gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe(headers=['text', 'confidence'])],
125
+ title=title,
126
+ description=description,
127
+ article=article,
128
+ examples=examples,
129
+ css=css,
130
+ enable_queue=True
131
+ ).launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ pillow
2
+ gradio
3
+ torch
4
+ easyocr