File size: 1,201 Bytes
dc3a13a c432b23 052f3e0 2c92c70 f9108f1 6bcfac7 db1d26e 6bcfac7 db1d26e 6bcfac7 db1d26e c432b23 f9108f1 2c92c70 db1d26e c26cd97 0c338a0 c26cd97 73e8fa5 de817ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import spaces
import PIL
from PIL import Image
from PIL import ImageDraw
import gradio as gr
import easyocr
@spaces.GPU
def process(img_path):
reader = easyocr.Reader(['en'])
results = reader.readtext(img_path)
ret = ""
rat = 0
pim = PIL.Image.open(img_path)
draw = ImageDraw.Draw(pim)
p0, p1, p2, p3 = 0, 0, 0, 0
for (bbox, txt, prob) in results:
if prob > rat:
ret = txt
rat = prob
p0, p1, p2, p3 = bbox
if rat != 0:
draw.line([*p0, *p1, *p2, *p3, *p0], fill = 'yellow', width = 2)
return [pim, ret]
title = '车架号识别展示'
description = '拖拽图片到识别区开始分析'
ip = gr.Image(sources = ['upload'], label = '上传图片', width = '100%', height = '40rem', type = 'filepath')
op = [gr.Image(sources = None, label = '处理结果', width = '100%', height = '40rem', type = 'pil'), gr.Textbox(show_label = False)]
css = """
#component-2 div.progress-text.svelte-ls20lj.meta-text { visibility: hidden; }
"""
gif = gr.Interface(fn = process, inputs = ip, outputs = op, title = title, description = description, batch = False, css = css, flagging_mode='never')
gif.launch(ssr_mode=False) |