fffiloni commited on
Commit
164ad79
1 Parent(s): b1a540c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
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
- image_size = 512
23
- source_img = gr.Image(source="upload", type="filepath", label="init_img", shape=(image_size, image_size))
24
  gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
25
 
26
- def infer(prompt, init_image):
27
- init_image.resize((768, 512))
28
- #image = pipe(prompt, init_image=init_image)["sample"][0]
 
 
 
 
 
 
 
 
 
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")