Spaces:
Runtime error
Runtime error
Update app
Browse files
utils.py
CHANGED
@@ -142,57 +142,9 @@ def mean_fill(img, mask):
|
|
142 |
img[mask < 1] = avg
|
143 |
return img, mask
|
144 |
|
145 |
-
"""
|
146 |
-
Apache-2.0 license
|
147 |
-
https://github.com/hafriedlander/stable-diffusion-grpcserver/blob/main/sdgrpcserver/services/generate.py
|
148 |
-
https://github.com/parlance-zz/g-diffuser-bot/tree/g-diffuser-bot-beta2
|
149 |
-
_handleImageAdjustment
|
150 |
-
"""
|
151 |
-
try:
|
152 |
-
from sd_grpcserver.sdgrpcserver import images
|
153 |
-
import torch
|
154 |
-
from math import sqrt
|
155 |
-
def handleImageAdjustment(array, adjustments):
|
156 |
-
tensor = images.fromPIL(Image.fromarray(array))
|
157 |
-
for adjustment in adjustments:
|
158 |
-
which = adjustment[0]
|
159 |
-
|
160 |
-
if which == "blur":
|
161 |
-
sigma = adjustment[1]
|
162 |
-
direction = adjustment[2]
|
163 |
-
|
164 |
-
if direction == "DOWN" or direction == "UP":
|
165 |
-
orig = tensor
|
166 |
-
repeatCount=256
|
167 |
-
sigma /= sqrt(repeatCount)
|
168 |
-
|
169 |
-
for _ in range(repeatCount):
|
170 |
-
tensor = images.gaussianblur(tensor, sigma)
|
171 |
-
if direction == "DOWN":
|
172 |
-
tensor = torch.minimum(tensor, orig)
|
173 |
-
else:
|
174 |
-
tensor = torch.maximum(tensor, orig)
|
175 |
-
else:
|
176 |
-
tensor = images.gaussianblur(tensor, adjustment.blur.sigma)
|
177 |
-
elif which == "invert":
|
178 |
-
tensor = images.invert(tensor)
|
179 |
-
elif which == "levels":
|
180 |
-
tensor = images.levels(tensor, adjustment[1], adjustment[2], adjustment[3], adjustment[4])
|
181 |
-
elif which == "channels":
|
182 |
-
tensor = images.channelmap(tensor, [adjustment.channels.r, adjustment.channels.g, adjustment.channels.b, adjustment.channels.a])
|
183 |
-
elif which == "rescale":
|
184 |
-
self.unimp("Rescale")
|
185 |
-
elif which == "crop":
|
186 |
-
tensor = images.crop(tensor, adjustment.crop.top, adjustment.crop.left, adjustment.crop.height, adjustment.crop.width)
|
187 |
-
return np.array(images.toPIL(tensor)[0])
|
188 |
-
except:
|
189 |
-
pass
|
190 |
-
|
191 |
def g_diffuser(img,mask):
|
192 |
-
|
193 |
-
|
194 |
-
out_mask=handleImageAdjustment(mask,adjustments)
|
195 |
-
return img, mask, out_mask
|
196 |
def dummy_fill(img,mask):
|
197 |
return img,mask
|
198 |
functbl = {
|
|
|
142 |
img[mask < 1] = avg
|
143 |
return img, mask
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
def g_diffuser(img,mask):
|
146 |
+
return img, mask
|
147 |
+
|
|
|
|
|
148 |
def dummy_fill(img,mask):
|
149 |
return img,mask
|
150 |
functbl = {
|