DerrylNessie commited on
Commit
e795847
1 Parent(s): 036cf29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -20,6 +20,13 @@ def midpoint(x1, y1, x2, y2):
20
  y_mid = int((y1 + y2)/2)
21
  return (x_mid, y_mid)
22
 
 
 
 
 
 
 
 
23
  def draw_mask(img, bounds):
24
  mask = np.zeros(img.shape[:2], dtype="uint8")
25
  for bound in bounds:
@@ -53,12 +60,14 @@ def inference(img, lang):
53
  bounds = reader.readtext(img.name)
54
  im = PIL.Image.open(img.name)
55
  img_array = np.array(im)
 
56
  im = draw_mask(img_array, bounds)
57
  im = Image.fromarray(im, 'RGB')
58
  lang = ""
 
59
  im.save('result.jpg')
60
 
61
- return ['result.jpg', pd.DataFrame(bounds). iloc[: , 1:2]]
62
 
63
  title = 'Manga Image Cleaner'
64
  description = 'Image inpainting and text detection demo with the use of EasyOCR and CV2. To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to test the program.'
@@ -75,7 +84,7 @@ gr.Interface(
75
  inference,
76
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
77
  [gr.outputs.Image(type='file', label='Output'),
78
- #gr.outputs.Image(type='file', label='Output'),
79
  gr.outputs.Dataframe()],
80
  title=title,
81
  description=description,
 
20
  y_mid = int((y1 + y2)/2)
21
  return (x_mid, y_mid)
22
 
23
+ def draw_boxes(image, bounds, color='yellow', width=2):
24
+ draw = ImageDraw.Draw(image)
25
+ for bound in bounds:
26
+ p0, p1, p2, p3 = bound[0]
27
+ draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
28
+ return image
29
+
30
  def draw_mask(img, bounds):
31
  mask = np.zeros(img.shape[:2], dtype="uint8")
32
  for bound in bounds:
 
60
  bounds = reader.readtext(img.name)
61
  im = PIL.Image.open(img.name)
62
  img_array = np.array(im)
63
+ img = draw_box(img_bounds)
64
  im = draw_mask(img_array, bounds)
65
  im = Image.fromarray(im, 'RGB')
66
  lang = ""
67
+ img.save('box.jpg')
68
  im.save('result.jpg')
69
 
70
+ return ['box.jpg', 'result.jpg', pd.DataFrame(bounds). iloc[: , 1:2]]
71
 
72
  title = 'Manga Image Cleaner'
73
  description = 'Image inpainting and text detection demo with the use of EasyOCR and CV2. To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to test the program.'
 
84
  inference,
85
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
86
  [gr.outputs.Image(type='file', label='Output'),
87
+ gr.outputs.Image(type='file', label='Output'),
88
  gr.outputs.Dataframe()],
89
  title=title,
90
  description=description,