JustKiddo commited on
Commit
6f5625c
·
verified ·
1 Parent(s): 8f4250d

Update app.py

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