Omnibus commited on
Commit
7b85041
β€’
1 Parent(s): 734bc82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -2
app.py CHANGED
@@ -6,6 +6,109 @@ import PIL
6
  from PIL import Image
7
  from PIL import ImageDraw
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  ocr_lang=[
10
  'abq',
11
  'ady',
@@ -103,7 +206,7 @@ def draw_boxes(image, bounds, color='blue', width=1):
103
  draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
104
  return image
105
 
106
- def detect(img, lang=[ocr_lang,'en']):
107
  reader = easyocr.Reader(lang)
108
  bounds = reader.readtext(img)
109
  im = PIL.Image.open(img)
@@ -112,10 +215,12 @@ def detect(img, lang=[ocr_lang,'en']):
112
 
113
  with gr.Blocks() as robot:
114
  im=gr.Image(type="filepath")
 
 
115
  go_btn=gr.Button()
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()
 
6
  from PIL import Image
7
  from PIL import ImageDraw
8
 
9
+ lang_id = {
10
+ "Afrikaans": "af",
11
+ "Amharic": "am",
12
+ "Arabic": "ar",
13
+ "Asturian": "ast",
14
+ "Azerbaijani": "az",
15
+ "Bashkir": "ba",
16
+ "Belarusian": "be",
17
+ "Bulgarian": "bg",
18
+ "Bengali": "bn",
19
+ "Breton": "br",
20
+ "Bosnian": "bs",
21
+ "Catalan": "ca",
22
+ "Cebuano": "ceb",
23
+ "Czech": "cs",
24
+ "Welsh": "cy",
25
+ "Danish": "da",
26
+ "German": "de",
27
+ "Greeek": "el",
28
+ "English": "en",
29
+ "Spanish": "es",
30
+ "Estonian": "et",
31
+ "Persian": "fa",
32
+ "Fulah": "ff",
33
+ "Finnish": "fi",
34
+ "French": "fr",
35
+ "Western Frisian": "fy",
36
+ "Irish": "ga",
37
+ "Gaelic": "gd",
38
+ "Galician": "gl",
39
+ "Gujarati": "gu",
40
+ "Hausa": "ha",
41
+ "Hebrew": "he",
42
+ "Hindi": "hi",
43
+ "Croatian": "hr",
44
+ "Haitian": "ht",
45
+ "Hungarian": "hu",
46
+ "Armenian": "hy",
47
+ "Indonesian": "id",
48
+ "Igbo": "ig",
49
+ "Iloko": "ilo",
50
+ "Icelandic": "is",
51
+ "Italian": "it",
52
+ "Japanese": "ja",
53
+ "Javanese": "jv",
54
+ "Georgian": "ka",
55
+ "Kazakh": "kk",
56
+ "Central Khmer": "km",
57
+ "Kannada": "kn",
58
+ "Korean": "ko",
59
+ "Luxembourgish": "lb",
60
+ "Ganda": "lg",
61
+ "Lingala": "ln",
62
+ "Lao": "lo",
63
+ "Lithuanian": "lt",
64
+ "Latvian": "lv",
65
+ "Malagasy": "mg",
66
+ "Macedonian": "mk",
67
+ "Malayalam": "ml",
68
+ "Mongolian": "mn",
69
+ "Marathi": "mr",
70
+ "Malay": "ms",
71
+ "Burmese": "my",
72
+ "Nepali": "ne",
73
+ "Dutch": "nl",
74
+ "Norwegian": "no",
75
+ "Northern Sotho": "ns",
76
+ "Occitan": "oc",
77
+ "Oriya": "or",
78
+ "Panjabi": "pa",
79
+ "Polish": "pl",
80
+ "Pushto": "ps",
81
+ "Portuguese": "pt",
82
+ "Romanian": "ro",
83
+ "Russian": "ru",
84
+ "Sindhi": "sd",
85
+ "Sinhala": "si",
86
+ "Slovak": "sk",
87
+ "Slovenian": "sl",
88
+ "Somali": "so",
89
+ "Albanian": "sq",
90
+ "Serbian": "sr",
91
+ "Swati": "ss",
92
+ "Sundanese": "su",
93
+ "Swedish": "sv",
94
+ "Swahili": "sw",
95
+ "Tamil": "ta",
96
+ "Thai": "th",
97
+ "Tagalog": "tl",
98
+ "Tswana": "tn",
99
+ "Turkish": "tr",
100
+ "Ukrainian": "uk",
101
+ "Urdu": "ur",
102
+ "Uzbek": "uz",
103
+ "Vietnamese": "vi",
104
+ "Wolof": "wo",
105
+ "Xhosa": "xh",
106
+ "Yiddish": "yi",
107
+ "Yoruba": "yo",
108
+ "Chinese": "zh",
109
+ "Zulu": "zu",
110
+ }
111
+
112
  ocr_lang=[
113
  'abq',
114
  'ady',
 
206
  draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
207
  return image
208
 
209
+ def detect(img, lang):
210
  reader = easyocr.Reader(lang)
211
  bounds = reader.readtext(img)
212
  im = PIL.Image.open(img)
 
215
 
216
  with gr.Blocks() as robot:
217
  im=gr.Image(type="filepath")
218
+ target_lang = gr.Dropdown(label="Target language", choices=list(lang_id.keys()),value="English")
219
+
220
  go_btn=gr.Button()
221
  out_im=gr.Image()
222
  with gr.Row():
223
  out_txt=gr.Textbox(lines=8)
224
  data_f=gr.Dataframe()
225
+ go_btn.click(detect,[im,target_lang],[out_im,out_txt,data_f])
226
  robot.queue(concurrency_count=10).launch()