9prayer commited on
Commit
73e8fa5
·
verified ·
1 Parent(s): b6607f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -6,30 +6,26 @@ from PIL import ImageDraw
6
  import gradio as gr
7
  import easyocr
8
 
9
- def draw_boxes(image, bounds, color='yellow', width = 2):
10
- draw = ImageDraw.Draw(image)
11
- for bound in bounds:
12
- p0, p1, p2, p3 = bound[0]
13
- draw.line([*p0, *p1, *p2, *p3, *p0], fill = color, width = width)
14
- return image
15
-
16
  @spaces.GPU
17
- def inference(img):
18
  reader = easyocr.Reader(['en'])
19
  bounds = reader.readtext(img.name)
20
  im = PIL.Image.open(img.name)
21
- draw_boxes(im, bounds)
 
 
 
22
  im.save('result.jpg')
23
  return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
24
 
25
  title = '车架号识别展示'
26
  description = '拖拽图片到识别区开始分析'
27
- ip = [gr.Image(sources = ['upload'], label = '上传图片', width = "100%", height = "40rem")]
28
  op = [gr.Image(sources = [], label = '处理结果', width = "100%", height = "40rem"), gr.Dataframe(col_count = (1, 'fixed'), show_label = False)]
29
  css = """
30
  table.svelte-y11bhb.svelte-y11bhb { max-width: 100%; overflow-x: hidden; }
31
  thead.svelte-y11bhb.svelte-y11bhb { visibility: hidden; }
32
  #component-2 div.progress-text.svelte-ls20lj.meta-text { visibility: hidden; }
33
  """
34
- gif = gr.Interface(fn = inference, inputs = ip, outputs = op, title = title, description = description, batch = False, css = css, flagging_mode='never')
35
  gif.launch()
 
6
  import gradio as gr
7
  import easyocr
8
 
 
 
 
 
 
 
 
9
  @spaces.GPU
10
+ def process(img):
11
  reader = easyocr.Reader(['en'])
12
  bounds = reader.readtext(img.name)
13
  im = PIL.Image.open(img.name)
14
+ draw = ImageDraw.Draw(image)
15
+ for bound in bounds:
16
+ p0, p1, p2, p3 = bound[0]
17
+ draw.line([*p0, *p1, *p2, *p3, *p0], fill = 'yellow', width = 2)
18
  im.save('result.jpg')
19
  return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
20
 
21
  title = '车架号识别展示'
22
  description = '拖拽图片到识别区开始分析'
23
+ ip = gr.Image(sources = ['upload'], label = '上传图片', width = "100%", height = "40rem")
24
  op = [gr.Image(sources = [], label = '处理结果', width = "100%", height = "40rem"), gr.Dataframe(col_count = (1, 'fixed'), show_label = False)]
25
  css = """
26
  table.svelte-y11bhb.svelte-y11bhb { max-width: 100%; overflow-x: hidden; }
27
  thead.svelte-y11bhb.svelte-y11bhb { visibility: hidden; }
28
  #component-2 div.progress-text.svelte-ls20lj.meta-text { visibility: hidden; }
29
  """
30
+ gif = gr.Interface(fn = process, inputs = ip, outputs = op, title = title, description = description, batch = False, css = css, flagging_mode='never')
31
  gif.launch()