Update app.py
Browse files
app.py
CHANGED
|
@@ -19,13 +19,22 @@ device="cpu"
|
|
| 19 |
|
| 20 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
| 21 |
pipe.to(device)
|
| 22 |
-
|
| 23 |
-
source_img = gr.Image(source="upload", type="filepath", label="init_img"
|
| 24 |
gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
|
| 25 |
|
| 26 |
-
def
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
images_list = pipe([prompt] * 2, init_image=init_image, strength=0.75)
|
| 30 |
images = []
|
| 31 |
safe_image = Image.open(r"unsafe.png")
|
|
|
|
| 19 |
|
| 20 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
| 21 |
pipe.to(device)
|
| 22 |
+
|
| 23 |
+
source_img = gr.Image(source="upload", type="filepath", label="init_img")
|
| 24 |
gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
|
| 25 |
|
| 26 |
+
def resize(width,img):
|
| 27 |
+
basewidth = width
|
| 28 |
+
img = Image.open(img)
|
| 29 |
+
wpercent = (basewidth/float(img.size[0]))
|
| 30 |
+
hsize = int((float(img.size[1])*float(wpercent)))
|
| 31 |
+
img = img.resize((basewidth,hsize), Image.Resampling.LANCZOS)
|
| 32 |
+
return img
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def infer(prompt, source_img):
|
| 36 |
+
init_image = resize(512,source_img)
|
| 37 |
+
init_image.save('source.png')
|
| 38 |
images_list = pipe([prompt] * 2, init_image=init_image, strength=0.75)
|
| 39 |
images = []
|
| 40 |
safe_image = Image.open(r"unsafe.png")
|