fix gradio issue
Browse files- app.py +10 -114
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -3,130 +3,26 @@ 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 |
-
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 |
-
torch.hub.download_url_to_file('https://i.imgur.com/mwQFd7G.jpeg', 'Hindi.jpeg')
|
| 16 |
-
|
| 17 |
-
def draw_boxes(image, bounds, color='yellow', width=2):
|
| 18 |
draw = ImageDraw.Draw(image)
|
| 19 |
for bound in bounds:
|
| 20 |
p0, p1, p2, p3 = bound[0]
|
| 21 |
-
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
| 22 |
return image
|
| 23 |
|
| 24 |
-
def inference(img
|
| 25 |
-
reader = easyocr.Reader(
|
| 26 |
bounds = reader.readtext(img.name)
|
| 27 |
im = PIL.Image.open(img.name)
|
| 28 |
draw_boxes(im, bounds)
|
| 29 |
im.save('result.jpg')
|
| 30 |
return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
|
| 31 |
|
| 32 |
-
title = '
|
| 33 |
-
description = '
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
"abq",
|
| 39 |
-
"ady",
|
| 40 |
-
"af",
|
| 41 |
-
"ang",
|
| 42 |
-
"ar",
|
| 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 |
-
gr.Interface(
|
| 123 |
-
inference,
|
| 124 |
-
[gr.inputs.Image(type='file', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['en'], label='language')],
|
| 125 |
-
[gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe(headers=['text', 'confidence'])],
|
| 126 |
-
title=title,
|
| 127 |
-
description=description,
|
| 128 |
-
article=article,
|
| 129 |
-
examples=examples,
|
| 130 |
-
css=css,
|
| 131 |
-
enable_queue=True
|
| 132 |
-
).launch(debug=True)
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
from PIL import ImageDraw
|
| 5 |
import gradio as gr
|
|
|
|
| 6 |
import easyocr
|
| 7 |
|
| 8 |
+
def draw_boxes(image, bounds, color='yellow', width = 2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
draw = ImageDraw.Draw(image)
|
| 10 |
for bound in bounds:
|
| 11 |
p0, p1, p2, p3 = bound[0]
|
| 12 |
+
draw.line([*p0, *p1, *p2, *p3, *p0], fill = color, width = width)
|
| 13 |
return image
|
| 14 |
|
| 15 |
+
def inference(img):
|
| 16 |
+
reader = easyocr.Reader(['en'])
|
| 17 |
bounds = reader.readtext(img.name)
|
| 18 |
im = PIL.Image.open(img.name)
|
| 19 |
draw_boxes(im, bounds)
|
| 20 |
im.save('result.jpg')
|
| 21 |
return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
|
| 22 |
|
| 23 |
+
title = '车架号识别展示'
|
| 24 |
+
description = '拖拽图片到识别区开始分析'
|
| 25 |
+
ip = [gr.Image(sources = ['upload'], label = '上传图片', width = "100%", height = "40rem")]
|
| 26 |
+
op = [gr.Image(sources = [], label = '处理结果', width = "100%", height = "40rem"), gr.Dataframe(col_count = 1, show_label = False)]
|
| 27 |
+
gif = gr.Interface(fn = inference, inputs = ip, outputs = op, title = title, description = description, batch = False, flagging_mode='never')
|
| 28 |
+
gif.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
|
|
| 1 |
opencv-python-headless
|
| 2 |
Pillow
|
| 3 |
gradio
|
| 4 |
-
torch
|
| 5 |
easyocr
|
|
|
|
| 1 |
+
pandas
|
| 2 |
opencv-python-headless
|
| 3 |
Pillow
|
| 4 |
gradio
|
|
|
|
| 5 |
easyocr
|