Spaces:
Runtime error
Runtime error
DerrylNessie
commited on
Commit
•
be299bc
1
Parent(s):
891aa18
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import pandas as pd
|
|
2 |
import PIL
|
3 |
from PIL import Image
|
4 |
from PIL import ImageDraw
|
5 |
-
from PIL import ImageFont
|
6 |
import gradio as gr
|
7 |
import torch
|
8 |
import easyocr
|
@@ -20,7 +19,7 @@ def midpoint(x1, y1, x2, y2):
|
|
20 |
x_mid = int((x1 + x2)/2)
|
21 |
y_mid = int((y1 + y2)/2)
|
22 |
return (x_mid, y_mid)
|
23 |
-
|
24 |
def draw_mask(img, bounds):
|
25 |
mask = np.zeros(img.shape[:2], dtype="uint8")
|
26 |
for bound in bounds:
|
@@ -37,7 +36,8 @@ def draw_mask(img, bounds):
|
|
37 |
thickness = int(math.sqrt((x2 - x1)**2 + (y2 - y1)**2))
|
38 |
|
39 |
cv.line(mask, (x_mid0, y_mid0), (x_mid1, y_mi1), 255, thickness)
|
40 |
-
img = cv.inpaint(img, mask, 3, cv.INPAINT_TELEA)
|
|
|
41 |
return(img)
|
42 |
|
43 |
def inference(img, lang):
|
@@ -53,15 +53,16 @@ def inference(img, lang):
|
|
53 |
bounds = reader.readtext(img.name)
|
54 |
im = PIL.Image.open(img.name)
|
55 |
img_array = np.array(im)
|
56 |
-
|
57 |
-
|
58 |
lang = ""
|
59 |
-
|
|
|
60 |
return ['result.jpg', pd.DataFrame(bounds). iloc[: , 1:2]]
|
61 |
|
62 |
title = 'Manga Image Cleaner'
|
63 |
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.'
|
64 |
-
article = "<p style='text-align: center'
|
65 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
66 |
examples = [['chinese.jpg',"chinese"], ['english.jpg',"english"], ['japanese.jpg',"japanese"], ['korean.jpg',"korean"]]
|
67 |
choices = [
|
@@ -74,7 +75,7 @@ gr.Interface(
|
|
74 |
inference,
|
75 |
[gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
|
76 |
[gr.outputs.Image(type='file', label='Output'),
|
77 |
-
gr.outputs.Image(type='file', label='Output'),
|
78 |
gr.outputs.Dataframe()],
|
79 |
title=title,
|
80 |
description=description,
|
|
|
2 |
import PIL
|
3 |
from PIL import Image
|
4 |
from PIL import ImageDraw
|
|
|
5 |
import gradio as gr
|
6 |
import torch
|
7 |
import easyocr
|
|
|
19 |
x_mid = int((x1 + x2)/2)
|
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:
|
|
|
36 |
thickness = int(math.sqrt((x2 - x1)**2 + (y2 - y1)**2))
|
37 |
|
38 |
cv.line(mask, (x_mid0, y_mid0), (x_mid1, y_mi1), 255, thickness)
|
39 |
+
img = cv.inpaint(img, mask, 3, cv.INPAINT_TELEA)
|
40 |
+
|
41 |
return(img)
|
42 |
|
43 |
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.'
|
65 |
+
article = "<p style='text-align: center'> <a>Ready-to-use image inpainting with supported languages such as: Chinese, English, Japanese, and Korean</a> | <a href='https://github.com/JaidedAI/EasyOCR'>Github OCR Repo</a> | <a href='https://towardsdatascience.com/remove-text-from-images-using-cv2-and-keras-ocr-24e7612ae4f4'>CV2 Reference</a></p>"
|
66 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
67 |
examples = [['chinese.jpg',"chinese"], ['english.jpg',"english"], ['japanese.jpg',"japanese"], ['korean.jpg',"korean"]]
|
68 |
choices = [
|
|
|
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,
|