vin-ocr / app.py
9prayer's picture
fix gradio issue
c1e8f69
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)