Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ from io import BytesIO
|
|
8 |
import os
|
9 |
MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
|
10 |
|
11 |
-
from diffusers import StableDiffusionPipeline
|
12 |
from diffusers import StableDiffusionImg2ImgPipeline
|
13 |
|
14 |
print("hello sylvain")
|
@@ -17,8 +17,8 @@ YOUR_TOKEN=MY_SECRET_TOKEN
|
|
17 |
|
18 |
device="cpu"
|
19 |
|
20 |
-
prompt_pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
21 |
-
prompt_pipe.to(device)
|
22 |
|
23 |
img_pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
24 |
img_pipe.to(device)
|
@@ -36,32 +36,22 @@ def resize(height,img):
|
|
36 |
|
37 |
|
38 |
def infer(prompt, source_img):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
else:
|
51 |
-
images_list = prompt_pipe([prompt] * 2)
|
52 |
-
images = []
|
53 |
-
safe_image = Image.open(r"unsafe.png")
|
54 |
-
for i, image in enumerate(images_list["sample"]):
|
55 |
-
if(images_list["nsfw_content_detected"][i]):
|
56 |
-
images.append(safe_image)
|
57 |
-
else:
|
58 |
-
images.append(image)
|
59 |
-
|
60 |
-
|
61 |
return images
|
|
|
62 |
print("Great sylvain ! Everything is working fine !")
|
63 |
|
64 |
-
title="Stable Diffusion CPU"
|
65 |
-
description="Stable Diffusion example using CPU and HF token. <br />Warning: Slow process... ~5/10 min inference time. <b>NSFW filter enabled.</b>"
|
66 |
|
67 |
gr.Interface(fn=infer, inputs=["text", source_img], outputs=gallery,title=title,description=description).launch(enable_queue=True)
|
|
|
8 |
import os
|
9 |
MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
|
10 |
|
11 |
+
#from diffusers import StableDiffusionPipeline
|
12 |
from diffusers import StableDiffusionImg2ImgPipeline
|
13 |
|
14 |
print("hello sylvain")
|
|
|
17 |
|
18 |
device="cpu"
|
19 |
|
20 |
+
#prompt_pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
21 |
+
#prompt_pipe.to(device)
|
22 |
|
23 |
img_pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
24 |
img_pipe.to(device)
|
|
|
36 |
|
37 |
|
38 |
def infer(prompt, source_img):
|
39 |
+
|
40 |
+
source_image = resize(512,source_img)
|
41 |
+
source_image.save('source.png')
|
42 |
+
images_list = img_pipe([prompt] * 2, init_image= source_image, strength=0.75)
|
43 |
+
images = []
|
44 |
+
safe_image = Image.open(r"unsafe.png")
|
45 |
+
for i, image in enumerate(images_list["sample"]):
|
46 |
+
if(images_list["nsfw_content_detected"][i]):
|
47 |
+
images.append(safe_image)
|
48 |
+
else:
|
49 |
+
images.append(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
return images
|
51 |
+
|
52 |
print("Great sylvain ! Everything is working fine !")
|
53 |
|
54 |
+
title="Img2Img Stable Diffusion CPU"
|
55 |
+
description="Img2Img Stable Diffusion example using CPU and HF token. <br />Warning: Slow process... ~5/10 min inference time. <b>NSFW filter enabled.</b>"
|
56 |
|
57 |
gr.Interface(fn=infer, inputs=["text", source_img], outputs=gallery,title=title,description=description).launch(enable_queue=True)
|