Update app.py
Browse files
app.py
CHANGED
@@ -36,13 +36,16 @@ def resize(value,img):
|
|
36 |
return img
|
37 |
|
38 |
|
39 |
-
def infer(source_img, prompt):
|
40 |
-
|
|
|
41 |
source_image = resize(512, source_img)
|
42 |
source_image.save('source.png')
|
43 |
-
|
|
|
44 |
images = []
|
45 |
safe_image = Image.open(r"unsafe.png")
|
|
|
46 |
for i, image in enumerate(images_list["sample"]):
|
47 |
if(images_list["nsfw_content_detected"][i]):
|
48 |
images.append(safe_image)
|
@@ -55,4 +58,10 @@ print("Great sylvain ! Everything is working fine !")
|
|
55 |
title="Img2Img Stable Diffusion CPU"
|
56 |
description="Img2Img Stable Diffusion example using CPU and HF token. <br />Warning: Slow process... ~5/10 min inference time. <b>NSFW filter enabled.</b>"
|
57 |
|
58 |
-
gr.Interface(fn=infer, inputs=[source_img,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
return img
|
37 |
|
38 |
|
39 |
+
def infer(source_img, prompt, guide, steps, seed, strength):
|
40 |
+
generator = torch.Generator('cpu').manual_seed(seed)
|
41 |
+
|
42 |
source_image = resize(512, source_img)
|
43 |
source_image.save('source.png')
|
44 |
+
|
45 |
+
images_list = img_pipe([prompt] * 2, init_image=source_image, strength=strength, guidance_scale=guide, num_inference_steps=steps)
|
46 |
images = []
|
47 |
safe_image = Image.open(r"unsafe.png")
|
48 |
+
|
49 |
for i, image in enumerate(images_list["sample"]):
|
50 |
if(images_list["nsfw_content_detected"][i]):
|
51 |
images.append(safe_image)
|
|
|
58 |
title="Img2Img Stable Diffusion CPU"
|
59 |
description="Img2Img Stable Diffusion example using CPU and HF token. <br />Warning: Slow process... ~5/10 min inference time. <b>NSFW filter enabled.</b>"
|
60 |
|
61 |
+
gr.Interface(fn=infer, inputs=[source_img,
|
62 |
+
"text",
|
63 |
+
gr.Slider(2, 15, value = 7, label = 'Guidence Scale'),
|
64 |
+
gr.Slider(10, 50, value = 25, step = 1, label = 'Number of Iterations'),
|
65 |
+
gr.Slider(label = "Seed", minimum = 0, maximum = 2147483647, step = 1, randomize = True),
|
66 |
+
gr.Slider(label='Strength', minimum = 0, maximum = 1, step = .05, value = .75)],
|
67 |
+
outputs=gallery,title=title,description=description, allow_flagging="manual", flagging_dir="flagged").queue(max_size=100).launch(enable_queue=True)
|