Spaces:
Runtime error
Runtime error
RohitGandikota
commited on
Commit
·
f231369
1
Parent(s):
d8de6d4
Update app.py
Browse files
app.py
CHANGED
@@ -3,34 +3,6 @@ import torch
|
|
3 |
from finetuning import FineTunedModel
|
4 |
from StableDiffuser import StableDiffuser
|
5 |
from train import train
|
6 |
-
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
7 |
-
from transformers import CLIPFeatureExtractor
|
8 |
-
|
9 |
-
|
10 |
-
def numpy_to_pil(images):
|
11 |
-
"""
|
12 |
-
Convert a numpy image or a batch of images to a PIL image.
|
13 |
-
"""
|
14 |
-
if images.ndim == 3:
|
15 |
-
images = images[None, ...]
|
16 |
-
images = (images * 255).round().astype("uint8")
|
17 |
-
if images.shape[-1] == 1:
|
18 |
-
# special case for grayscale (single channel) images
|
19 |
-
pil_images = [Image.fromarray(image.squeeze(), mode="L") for image in images]
|
20 |
-
else:
|
21 |
-
pil_images = [Image.fromarray(image) for image in images]
|
22 |
-
|
23 |
-
return pil_images
|
24 |
-
|
25 |
-
def run_safety_checker(image):
|
26 |
-
|
27 |
-
feature_extractor = CLIPFeatureExtractor()
|
28 |
-
safety_checker = StableDiffusionSafetyChecker()
|
29 |
-
safety_checker_input = feature_extractor(numpy_to_pil(image), return_tensors="pt").to('cuda')
|
30 |
-
image, has_nsfw_concept = safety_checker(
|
31 |
-
images=image, clip_input=safety_checker_input.pixel_values
|
32 |
-
)
|
33 |
-
return image, has_nsfw_concept
|
34 |
|
35 |
import os
|
36 |
model_map = {'Van Gogh' : 'models/vangogh.pt',
|
@@ -258,7 +230,7 @@ class Demo:
|
|
258 |
n_steps=50,
|
259 |
generator=generator
|
260 |
)
|
261 |
-
|
262 |
|
263 |
orig_image = images[0][0]
|
264 |
|
@@ -273,7 +245,7 @@ class Demo:
|
|
273 |
n_steps=50,
|
274 |
generator=generator
|
275 |
)
|
276 |
-
|
277 |
edited_image = images[0][0]
|
278 |
|
279 |
del finetuner
|
|
|
3 |
from finetuning import FineTunedModel
|
4 |
from StableDiffuser import StableDiffuser
|
5 |
from train import train
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
import os
|
8 |
model_map = {'Van Gogh' : 'models/vangogh.pt',
|
|
|
230 |
n_steps=50,
|
231 |
generator=generator
|
232 |
)
|
233 |
+
|
234 |
|
235 |
orig_image = images[0][0]
|
236 |
|
|
|
245 |
n_steps=50,
|
246 |
generator=generator
|
247 |
)
|
248 |
+
|
249 |
edited_image = images[0][0]
|
250 |
|
251 |
del finetuner
|