Update app.py
Browse files
app.py
CHANGED
@@ -4,30 +4,29 @@ from PIL import Image
|
|
4 |
|
5 |
from lambda_diffusers import StableDiffusionImageEmbedPipeline
|
6 |
|
7 |
-
def
|
8 |
-
input_im,
|
9 |
-
scale=3.0,
|
10 |
-
n_samples=2,
|
11 |
-
steps=25,
|
12 |
-
seed=0,
|
13 |
-
):
|
14 |
|
15 |
-
generator = torch.Generator(device=device).manual_seed(int(seed))
|
16 |
-
|
17 |
images_list = pipe(
|
18 |
n_samples*[input_im],
|
19 |
guidance_scale=scale,
|
20 |
num_inference_steps=steps,
|
21 |
generator=generator,
|
22 |
)
|
23 |
-
|
24 |
-
images = []
|
25 |
for i, image in enumerate(images_list["sample"]):
|
26 |
if(images_list["nsfw_content_detected"][i]):
|
27 |
safe_image = Image.open(r"unsafe.png")
|
28 |
images.append(safe_image)
|
29 |
else:
|
30 |
images.append(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
return images
|
32 |
|
33 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
@@ -40,7 +39,7 @@ pipe = pipe.to(device)
|
|
40 |
inputs = [
|
41 |
gr.Image(),
|
42 |
gr.Slider(0, 25, value=3, step=1, label="Guidance scale"),
|
43 |
-
gr.Slider(1, 2, value=
|
44 |
gr.Slider(5, 50, value=25, step=5, label="Steps"),
|
45 |
gr.Number(0, labal="Seed", precision=0)
|
46 |
]
|
|
|
4 |
|
5 |
from lambda_diffusers import StableDiffusionImageEmbedPipeline
|
6 |
|
7 |
+
def ask(input_im, scale, n_samples, steps, seed):
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
|
|
|
|
9 |
images_list = pipe(
|
10 |
n_samples*[input_im],
|
11 |
guidance_scale=scale,
|
12 |
num_inference_steps=steps,
|
13 |
generator=generator,
|
14 |
)
|
|
|
|
|
15 |
for i, image in enumerate(images_list["sample"]):
|
16 |
if(images_list["nsfw_content_detected"][i]):
|
17 |
safe_image = Image.open(r"unsafe.png")
|
18 |
images.append(safe_image)
|
19 |
else:
|
20 |
images.append(image)
|
21 |
+
|
22 |
+
def main(input_im, scale, n_samples, steps, seed):
|
23 |
+
|
24 |
+
generator = torch.Generator(device=device).manual_seed(int(seed))
|
25 |
+
|
26 |
+
images = []
|
27 |
+
ask(input_im, scale, n_samples, steps, seed)
|
28 |
+
ask(input_im, scale, n_samples, steps, seed)
|
29 |
+
|
30 |
return images
|
31 |
|
32 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
39 |
inputs = [
|
40 |
gr.Image(),
|
41 |
gr.Slider(0, 25, value=3, step=1, label="Guidance scale"),
|
42 |
+
gr.Slider(1, 2, value=2, step=1, label="Number images"),
|
43 |
gr.Slider(5, 50, value=25, step=5, label="Steps"),
|
44 |
gr.Number(0, labal="Seed", precision=0)
|
45 |
]
|