Spaces:
Runtime error
Runtime error
DerrylNessie
commited on
Commit
•
93107a1
1
Parent(s):
1a2e1d4
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from PIL import ImageDraw
|
|
5 |
import gradio as gr
|
6 |
import torch
|
7 |
import easyocr
|
8 |
-
import cv2
|
9 |
import math
|
10 |
import numpy as np
|
11 |
|
@@ -22,6 +22,10 @@ def draw_mask(img, 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):
|
27 |
if lang == "english":
|
@@ -37,22 +41,21 @@ def inference(img, lang):
|
|
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 |
#img_inpainted = cv2.inpaint(im, mask, 7, cv2.INPAINT_NS)
|
43 |
#remove_text(im, mask, bounds)
|
44 |
lang = ""
|
45 |
im.save('result.jpg')
|
46 |
mask.save('mask.png')
|
|
|
47 |
#img_inpainted.save('inpaint.jpg')
|
48 |
-
|
49 |
-
mask = cv.imread('mask.png',0)
|
50 |
-
dst = cv.inpaint(img,mask,3,cv.INPAINT_TELEA)
|
51 |
#img_inpainted = cv2.inpaint(im, mask, 7, cv2.INPAINT_TELEA)
|
52 |
#cv2.imwrite('dst.png', dst)
|
53 |
#dst.save('dst.png')
|
54 |
-
return (
|
55 |
-
#return ['result.jpg', 'dst.png', pd.DataFrame(bounds). iloc[: , 1:2]]
|
56 |
|
57 |
title = 'EasyOCR'
|
58 |
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.'
|
@@ -68,10 +71,10 @@ choices = [
|
|
68 |
gr.Interface(
|
69 |
inference,
|
70 |
[gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
|
71 |
-
gr.outputs.Image(type='file', label='Output'),
|
72 |
-
|
73 |
#gr.outputs.Image(type='file', label='Output'),
|
74 |
-
|
75 |
title=title,
|
76 |
description=description,
|
77 |
article=article,
|
|
|
5 |
import gradio as gr
|
6 |
import torch
|
7 |
import easyocr
|
8 |
+
import cv2
|
9 |
import math
|
10 |
import numpy as np
|
11 |
|
|
|
22 |
p0, p1, p2, p3 = bound[0]
|
23 |
draw.polygon((*p0, *p1, *p2, *p3, *p0), fill=255)
|
24 |
return img
|
25 |
+
|
26 |
+
def masking(img, mask):
|
27 |
+
img = cv2.inpaint(img, mask, 3, cv2.INPAINT_TELEA)
|
28 |
+
return img
|
29 |
|
30 |
def inference(img, lang):
|
31 |
if lang == "english":
|
|
|
41 |
im = PIL.Image.open(img.name)
|
42 |
#mask = PIL.Image.open(img.name)
|
43 |
mask = Image.new("L", im.size, 0)
|
|
|
44 |
draw_mask(mask, bounds)
|
45 |
+
|
46 |
+
final = masking(im, mask)
|
47 |
#img_inpainted = cv2.inpaint(im, mask, 7, cv2.INPAINT_NS)
|
48 |
#remove_text(im, mask, bounds)
|
49 |
lang = ""
|
50 |
im.save('result.jpg')
|
51 |
mask.save('mask.png')
|
52 |
+
final.save('final.png')
|
53 |
#img_inpainted.save('inpaint.jpg')
|
54 |
+
#dst = cv.inpaint(img,mask,3,cv.INPAINT_TELEA)
|
|
|
|
|
55 |
#img_inpainted = cv2.inpaint(im, mask, 7, cv2.INPAINT_TELEA)
|
56 |
#cv2.imwrite('dst.png', dst)
|
57 |
#dst.save('dst.png')
|
58 |
+
return ['result.jpg', 'mask.png', pd.DataFrame(bounds). iloc[: , 1:2]]
|
|
|
59 |
|
60 |
title = 'EasyOCR'
|
61 |
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.'
|
|
|
71 |
gr.Interface(
|
72 |
inference,
|
73 |
[gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
|
74 |
+
[gr.outputs.Image(type='file', label='Output'),
|
75 |
+
gr.outputs.Image(type='file', label='Output'),
|
76 |
#gr.outputs.Image(type='file', label='Output'),
|
77 |
+
gr.outputs.Dataframe()],
|
78 |
title=title,
|
79 |
description=description,
|
80 |
article=article,
|