Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -78,36 +78,11 @@ def brush_stroke_mask(img, color=(255,255,255)):
|
|
78 |
mask = generate_mask(height, width, img)
|
79 |
return mask
|
80 |
|
81 |
-
def
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
# if both the width and height are None, then return the
|
88 |
-
# original image
|
89 |
-
if width is None and height is None:
|
90 |
-
return image
|
91 |
-
|
92 |
-
# check to see if the width is None
|
93 |
-
if width is None:
|
94 |
-
# calculate the ratio of the height and construct the
|
95 |
-
# dimensions
|
96 |
-
r = height / float(h)
|
97 |
-
dim = (int(w * r), height)
|
98 |
-
|
99 |
-
# otherwise, the height is None
|
100 |
-
else:
|
101 |
-
# calculate the ratio of the width and construct the
|
102 |
-
# dimensions
|
103 |
-
r = width / float(w)
|
104 |
-
dim = (width, int(h * r))
|
105 |
-
|
106 |
-
# resize the image
|
107 |
-
resized = cv2.resize(image, dim, interpolation = inter)
|
108 |
-
|
109 |
-
# return the resized image
|
110 |
-
return resized
|
111 |
|
112 |
def inference(file, mode):
|
113 |
|
@@ -132,7 +107,7 @@ def inference(file, mode):
|
|
132 |
return os.path.join("output.png")
|
133 |
elif mode == "inpainting":
|
134 |
im1 = cv2.imread(file, cv2.IMREAD_COLOR)
|
135 |
-
im2 =
|
136 |
model = {'name':'GPEN-Inpainting-1024', 'size':1024}
|
137 |
faceinpainter = FaceInpainting(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
|
138 |
im3 = np.asarray(brush_stroke_mask(Image.fromarray(im2)))
|
|
|
78 |
mask = generate_mask(height, width, img)
|
79 |
return mask
|
80 |
|
81 |
+
def resize(self,image,width = 1024):
|
82 |
+
aspect_ratio = float(image.shape[1])/float(image.shape[0])
|
83 |
+
height = width/aspect_ratio
|
84 |
+
image = cv2.resize(image, (int(height),int(width)))
|
85 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
def inference(file, mode):
|
88 |
|
|
|
107 |
return os.path.join("output.png")
|
108 |
elif mode == "inpainting":
|
109 |
im1 = cv2.imread(file, cv2.IMREAD_COLOR)
|
110 |
+
im2 = resize(im1, width = 1024)
|
111 |
model = {'name':'GPEN-Inpainting-1024', 'size':1024}
|
112 |
faceinpainter = FaceInpainting(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
|
113 |
im3 = np.asarray(brush_stroke_mask(Image.fromarray(im2)))
|