DerrylNessie commited on
Commit
93ce6b7
1 Parent(s): 36ab272

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -16,11 +16,11 @@ def midpoint(x1, y1, x2, y2):
16
  y_mid = int((y1 + y2)/2)
17
  return (x_mid, y_mid)
18
 
19
- def draw_mask(img, bounds, color='yellow', width=2):
20
  draw = ImageDraw.Draw(img)
21
  for bound in bounds:
22
  p0, p1, p2, p3 = bound[0]
23
- draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
24
  return img
25
 
26
  def inference(img, lang):
@@ -36,14 +36,14 @@ def inference(img, lang):
36
  bounds = reader.readtext(img.name)
37
  im = PIL.Image.open(img.name)
38
  #mask = PIL.Image.open(img.name)
39
- #mask = Image.new("L", im.size, 0)
40
 
41
- draw_mask(im, bounds)
42
  #remove_text(im, mask, bounds)
43
  lang = ""
44
  im.save('result.jpg')
45
- #mask.save('mask.png')
46
- return ['result.jpg', pd.DataFrame(bounds). iloc[: , 1:2]]
47
 
48
  title = 'EasyOCR'
49
  description = 'Gradio demo for EasyOCR. EasyOCR demo supports 80+ languages.To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to load them. Read more at the links below.'
@@ -59,7 +59,7 @@ choices = [
59
  gr.Interface(
60
  inference,
61
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
62
- [gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe()],
63
  title=title,
64
  description=description,
65
  article=article,
 
16
  y_mid = int((y1 + y2)/2)
17
  return (x_mid, y_mid)
18
 
19
+ def draw_mask(img, bounds):
20
  draw = ImageDraw.Draw(img)
21
  for bound in bounds:
22
  p0, p1, p2, p3 = bound[0]
23
+ draw.polygon((*p0, *p1, *p2, *p3, *p0), fill=255)
24
  return img
25
 
26
  def inference(img, lang):
 
36
  bounds = reader.readtext(img.name)
37
  im = PIL.Image.open(img.name)
38
  #mask = PIL.Image.open(img.name)
39
+ mask = Image.new("L", im.size, 0)
40
 
41
+ draw_mask(mask, bounds)
42
  #remove_text(im, mask, bounds)
43
  lang = ""
44
  im.save('result.jpg')
45
+ mask.save('mask.png')
46
+ return ['result.jpg', 'mask.jpg', pd.DataFrame(bounds). iloc[: , 1:2]]
47
 
48
  title = 'EasyOCR'
49
  description = 'Gradio demo for EasyOCR. EasyOCR demo supports 80+ languages.To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to load them. Read more at the links below.'
 
59
  gr.Interface(
60
  inference,
61
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
62
+ [gr.outputs.Image(type='file', label='Output'), gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe()],
63
  title=title,
64
  description=description,
65
  article=article,