Update app.py
Browse files
app.py
CHANGED
|
@@ -21,112 +21,62 @@ def draw_boxes(image, bounds, color='yellow', width=2):
|
|
| 21 |
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
| 22 |
return image
|
| 23 |
|
| 24 |
-
def inference(
|
| 25 |
reader = easyocr.Reader(lang)
|
| 26 |
-
bounds = reader.readtext(
|
| 27 |
-
im = PIL.Image.open(
|
| 28 |
draw_boxes(im, bounds)
|
| 29 |
im.save('result.jpg')
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
title = 'EasyOCR'
|
| 33 |
-
description =
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
|
|
|
| 37 |
choices = [
|
| 38 |
-
"abq",
|
| 39 |
-
"
|
| 40 |
-
"
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"as",
|
| 44 |
-
"ava",
|
| 45 |
-
"az",
|
| 46 |
-
"be",
|
| 47 |
-
"bg",
|
| 48 |
-
"bh",
|
| 49 |
-
"bho",
|
| 50 |
-
"bn",
|
| 51 |
-
"bs",
|
| 52 |
-
"ch_sim",
|
| 53 |
-
"ch_tra",
|
| 54 |
-
"che",
|
| 55 |
-
"cs",
|
| 56 |
-
"cy",
|
| 57 |
-
"da",
|
| 58 |
-
"dar",
|
| 59 |
-
"de",
|
| 60 |
-
"en",
|
| 61 |
-
"es",
|
| 62 |
-
"et",
|
| 63 |
-
"fa",
|
| 64 |
-
"fr",
|
| 65 |
-
"ga",
|
| 66 |
-
"gom",
|
| 67 |
-
"hi",
|
| 68 |
-
"hr",
|
| 69 |
-
"hu",
|
| 70 |
-
"id",
|
| 71 |
-
"inh",
|
| 72 |
-
"is",
|
| 73 |
-
"it",
|
| 74 |
-
"ja",
|
| 75 |
-
"kbd",
|
| 76 |
-
"kn",
|
| 77 |
-
"ko",
|
| 78 |
-
"ku",
|
| 79 |
-
"la",
|
| 80 |
-
"lbe",
|
| 81 |
-
"lez",
|
| 82 |
-
"lt",
|
| 83 |
-
"lv",
|
| 84 |
-
"mah",
|
| 85 |
-
"mai",
|
| 86 |
-
"mi",
|
| 87 |
-
"mn",
|
| 88 |
-
"mr",
|
| 89 |
-
"ms",
|
| 90 |
-
"mt",
|
| 91 |
-
"ne",
|
| 92 |
-
"new",
|
| 93 |
-
"nl",
|
| 94 |
-
"no",
|
| 95 |
-
"oc",
|
| 96 |
-
"pi",
|
| 97 |
-
"pl",
|
| 98 |
-
"pt",
|
| 99 |
-
"ro",
|
| 100 |
-
"ru",
|
| 101 |
-
"rs_cyrillic",
|
| 102 |
-
"rs_latin",
|
| 103 |
-
"sck",
|
| 104 |
-
"sk",
|
| 105 |
-
"sl",
|
| 106 |
-
"sq",
|
| 107 |
-
"sv",
|
| 108 |
-
"sw",
|
| 109 |
-
"ta",
|
| 110 |
-
"tab",
|
| 111 |
-
"te",
|
| 112 |
-
"th",
|
| 113 |
-
"tjk",
|
| 114 |
-
"tl",
|
| 115 |
-
"tr",
|
| 116 |
-
"ug",
|
| 117 |
-
"uk",
|
| 118 |
-
"ur",
|
| 119 |
-
"uz",
|
| 120 |
-
"vi"
|
| 121 |
]
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
title=title,
|
| 127 |
description=description,
|
| 128 |
article=article,
|
| 129 |
examples=examples,
|
| 130 |
css=css,
|
| 131 |
enable_queue=True
|
| 132 |
-
|
|
|
|
|
|
|
|
|
| 21 |
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
| 22 |
return image
|
| 23 |
|
| 24 |
+
def inference(img_path, lang):
|
| 25 |
reader = easyocr.Reader(lang)
|
| 26 |
+
bounds = reader.readtext(img_path)
|
| 27 |
+
im = PIL.Image.open(img_path)
|
| 28 |
draw_boxes(im, bounds)
|
| 29 |
im.save('result.jpg')
|
| 30 |
+
|
| 31 |
+
# return dataframe with only text + confidence
|
| 32 |
+
df = pd.DataFrame(bounds)[[1, 2]]
|
| 33 |
+
df.columns = ["text", "confidence"]
|
| 34 |
+
|
| 35 |
+
return 'result.jpg', df
|
| 36 |
|
| 37 |
title = 'EasyOCR'
|
| 38 |
+
description = """
|
| 39 |
+
EasyOCR demo supports 80+ languages.
|
| 40 |
+
Upload an image and choose a language to extract text.
|
| 41 |
+
"""
|
| 42 |
+
article = "<p style='text-align: center'><a href='https://www.jaided.ai/easyocr/'>EasyOCR Website</a> | <a href='https://github.com/JaidedAI/EasyOCR'>GitHub Repo</a></p>"
|
| 43 |
+
|
| 44 |
+
examples = [
|
| 45 |
+
['english.png', ['en']],
|
| 46 |
+
['thai.jpg', ['th']],
|
| 47 |
+
['french.jpg', ['fr', 'en']],
|
| 48 |
+
['chinese.jpg', ['ch_sim', 'en']],
|
| 49 |
+
['japanese.jpg', ['ja', 'en']],
|
| 50 |
+
['korean.png', ['ko', 'en']],
|
| 51 |
+
['Hindi.jpeg', ['hi', 'en']]
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
| 55 |
+
|
| 56 |
choices = [
|
| 57 |
+
"abq","ady","af","ang","ar","as","ava","az","be","bg","bh","bho","bn","bs","ch_sim","ch_tra","che",
|
| 58 |
+
"cs","cy","da","dar","de","en","es","et","fa","fr","ga","gom","hi","hr","hu","id","inh","is","it",
|
| 59 |
+
"ja","kbd","kn","ko","ku","la","lbe","lez","lt","lv","mah","mai","mi","mn","mr","ms","mt","ne",
|
| 60 |
+
"new","nl","no","oc","pi","pl","pt","ro","ru","rs_cyrillic","rs_latin","sck","sk","sl","sq","sv",
|
| 61 |
+
"sw","ta","tab","te","th","tjk","tl","tr","ug","uk","ur","uz","vi"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
]
|
| 63 |
+
|
| 64 |
+
demo = gr.Interface(
|
| 65 |
+
fn=inference,
|
| 66 |
+
inputs=[
|
| 67 |
+
gr.Image(type="filepath", label="Input Image"),
|
| 68 |
+
gr.CheckboxGroup(choices=choices, value=["en"], label="Language")
|
| 69 |
+
],
|
| 70 |
+
outputs=[
|
| 71 |
+
gr.Image(label="Output"),
|
| 72 |
+
gr.Dataframe(label="Detected Text")
|
| 73 |
+
],
|
| 74 |
title=title,
|
| 75 |
description=description,
|
| 76 |
article=article,
|
| 77 |
examples=examples,
|
| 78 |
css=css,
|
| 79 |
enable_queue=True
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
demo.launch(debug=True)
|