Update app.py
Browse files
app.py
CHANGED
|
@@ -7,8 +7,8 @@ from PIL import Image
|
|
| 7 |
import os
|
| 8 |
MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
|
| 9 |
|
| 10 |
-
from diffusers import StableDiffusionPipeline
|
| 11 |
-
|
| 12 |
|
| 13 |
print("hello sylvain")
|
| 14 |
|
|
@@ -16,15 +16,15 @@ YOUR_TOKEN=MY_SECRET_TOKEN
|
|
| 16 |
|
| 17 |
device="cpu"
|
| 18 |
|
| 19 |
-
pipe =
|
| 20 |
pipe.to(device)
|
| 21 |
|
| 22 |
gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
|
| 23 |
|
| 24 |
-
def infer(prompt):
|
| 25 |
|
| 26 |
#image = pipe(prompt, init_image=init_image)["sample"][0]
|
| 27 |
-
images_list = pipe([prompt] *
|
| 28 |
images = []
|
| 29 |
safe_image = Image.open(r"unsafe.png")
|
| 30 |
for i, image in enumerate(images_list["sample"]):
|
|
@@ -40,4 +40,4 @@ print("Great sylvain ! Everything is working fine !")
|
|
| 40 |
title="Stable Diffusion CPU"
|
| 41 |
description="Stable Diffusion example using CPU and HF token. <br />Warning: Slow process... ~5/10 min inference time. <b>NSFW filter enabled.</b>"
|
| 42 |
|
| 43 |
-
gr.Interface(fn=infer, inputs="text", outputs=gallery,title=title,description=description).launch(enable_queue=True)
|
|
|
|
| 7 |
import os
|
| 8 |
MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
|
| 9 |
|
| 10 |
+
#from diffusers import StableDiffusionPipeline
|
| 11 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
| 12 |
|
| 13 |
print("hello sylvain")
|
| 14 |
|
|
|
|
| 16 |
|
| 17 |
device="cpu"
|
| 18 |
|
| 19 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
| 20 |
pipe.to(device)
|
| 21 |
|
| 22 |
gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
|
| 23 |
|
| 24 |
+
def infer(prompt, init_image):
|
| 25 |
|
| 26 |
#image = pipe(prompt, init_image=init_image)["sample"][0]
|
| 27 |
+
images_list = pipe([prompt] * 2, init_image=init_image, strength=0.75)
|
| 28 |
images = []
|
| 29 |
safe_image = Image.open(r"unsafe.png")
|
| 30 |
for i, image in enumerate(images_list["sample"]):
|
|
|
|
| 40 |
title="Stable Diffusion CPU"
|
| 41 |
description="Stable Diffusion example using CPU and HF token. <br />Warning: Slow process... ~5/10 min inference time. <b>NSFW filter enabled.</b>"
|
| 42 |
|
| 43 |
+
gr.Interface(fn=infer, inputs=["text","image"], outputs=gallery,title=title,description=description).launch(enable_queue=True)
|