DerrylNessie commited on
Commit
ed65392
1 Parent(s): a56aa0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -18,10 +18,16 @@ def midpoint(x1, y1, x2, y2):
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
 
24
- """
25
  x0,y0 = p0
26
  x1,y1 = p1
27
  x2,y2 = p2
@@ -34,14 +40,12 @@ def draw_mask(img, bounds):
34
  mask = np.zeros(img.shape[:2], dtype="uint8")
35
  cv2.line(mask, (x_mid0, y_mid0), (x_mid1, y_mi1), 255, thickness)
36
  img = cv2.inpaint(img, mask, 7, cv2.INPAINT_NS)
37
- """
38
-
39
  draw.polygon((*p0, *p1, *p2, *p3), fill=255)
40
 
41
  #masking
42
 
43
- return img
44
- """
45
  def remove_text(img,imgwmask):
46
  masked = cv2.bitwise_and(img, img, mask=imgwmask)
47
  return img
@@ -58,7 +62,7 @@ def inference(img, lang):
58
  reader = easyocr.Reader(lang)
59
  bounds = reader.readtext(img.name)
60
  im = PIL.Image.open(img.name)
61
- mask = PIL.Image.new("L", im1.size, 0)
62
  #w, h = im.size
63
 
64
  draw_mask(im, bounds)
@@ -66,7 +70,7 @@ def inference(img, lang):
66
  lang = ""
67
  im.save('result.png')
68
  #mask.save('mask.png')
69
- return ['result.png', 'mask.png', pd.DataFrame(bounds). iloc[: , 1:2]]
70
 
71
  title = 'EasyOCR'
72
  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.'
@@ -82,7 +86,7 @@ choices = [
82
  gr.Interface(
83
  inference,
84
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
85
- [gr.outputs.Image(type='file', label='Output'), gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe()],
86
  title=title,
87
  description=description,
88
  article=article,
 
18
 
19
  def draw_mask(img, bounds):
20
  draw = ImageDraw.Draw(img)
21
+
22
+ for bound in bounds:
23
+ p0, p1, p2, p3 = bound[0]
24
+ draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
25
+
26
+ return imag
27
+ """
28
  for bound in bounds:
29
  p0, p1, p2, p3 = bound[0]
30
 
 
31
  x0,y0 = p0
32
  x1,y1 = p1
33
  x2,y2 = p2
 
40
  mask = np.zeros(img.shape[:2], dtype="uint8")
41
  cv2.line(mask, (x_mid0, y_mid0), (x_mid1, y_mi1), 255, thickness)
42
  img = cv2.inpaint(img, mask, 7, cv2.INPAINT_NS)
43
+
 
44
  draw.polygon((*p0, *p1, *p2, *p3), fill=255)
45
 
46
  #masking
47
 
48
+ return img
 
49
  def remove_text(img,imgwmask):
50
  masked = cv2.bitwise_and(img, img, mask=imgwmask)
51
  return img
 
62
  reader = easyocr.Reader(lang)
63
  bounds = reader.readtext(img.name)
64
  im = PIL.Image.open(img.name)
65
+ #mask = PIL.Image.new("L", im1.size, 0)
66
  #w, h = im.size
67
 
68
  draw_mask(im, bounds)
 
70
  lang = ""
71
  im.save('result.png')
72
  #mask.save('mask.png')
73
+ return ['result.png', pd.DataFrame(bounds). iloc[: , 1:2]]
74
 
75
  title = 'EasyOCR'
76
  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.'
 
86
  gr.Interface(
87
  inference,
88
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
89
+ [gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe()],
90
  title=title,
91
  description=description,
92
  article=article,