hantech commited on
Commit
cf6b359
β€’
1 Parent(s): 96f054d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -37,9 +37,9 @@ def draw_boxes(image, bounds, color='yellow', width=2):
37
  draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
38
  return image
39
 
40
- def inference(img, lang):
41
  reader = easyocr.Reader(lang)
42
- bounds = reader.readtext(img.name)
43
  new_bounds=[]
44
  for (bbox, text, prob) in bounds:
45
  y0 = bbox[0].min()
@@ -48,7 +48,7 @@ def inference(img, lang):
48
  x1 = bbox[1].max()
49
 
50
  # crop the region of interest (ROI)
51
- img = Image.open(img.name)
52
  img = img[y0:y1, x0:x1]
53
  img = process_input(img, config['dataset']['image_height'],
54
  config['dataset']['image_min_width'], config['dataset']['image_max_width'])
@@ -152,8 +152,8 @@ choices = [
152
  ]
153
  gr.Interface(
154
  inference,
155
- [gr.inputs.Image(type='file', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['en'], label='language')],
156
- [gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe(headers=['text', 'confidence'])],
157
  title=title,
158
  description=description,
159
  article=article,
 
37
  draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
38
  return image
39
 
40
+ def inference(filepath, lang):
41
  reader = easyocr.Reader(lang)
42
+ bounds = reader.readtext(filepath)
43
  new_bounds=[]
44
  for (bbox, text, prob) in bounds:
45
  y0 = bbox[0].min()
 
48
  x1 = bbox[1].max()
49
 
50
  # crop the region of interest (ROI)
51
+ img = Image.open(filepath)
52
  img = img[y0:y1, x0:x1]
53
  img = process_input(img, config['dataset']['image_height'],
54
  config['dataset']['image_min_width'], config['dataset']['image_max_width'])
 
152
  ]
153
  gr.Interface(
154
  inference,
155
+ [gr.inputs.Image(type='filepath', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['en'], label='language')],
156
+ [gr.outputs.Image(type='filepath', label='Output'), gr.outputs.Dataframe(headers=['text', 'confidence'])],
157
  title=title,
158
  description=description,
159
  article=article,