fffiloni commited on
Commit
5665597
1 Parent(s): df7806f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -20,12 +20,23 @@ device="cpu"
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="numpy")
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
- print(init_image)
28
- return init_image
 
 
 
 
 
 
 
 
 
 
 
29
  print("Great sylvain ! Everything is working fine !")
30
 
31
  title="Stable Diffusion CPU"
 
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="pil", 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 = Image.open(BytesIO(init_image)).convert("RGB")
28
+ init_image = init_image.resize((768, 512))
29
+ #image = pipe(prompt, init_image=init_image)["sample"][0]
30
+ images_list = pipe([prompt] * 2, init_image=init_image, strength=0.75)
31
+ images = []
32
+ safe_image = Image.open(r"unsafe.png")
33
+ for i, image in enumerate(images_list["sample"]):
34
+ if(images_list["nsfw_content_detected"][i]):
35
+ images.append(safe_image)
36
+ else:
37
+ images.append(image)
38
+
39
+ return images
40
  print("Great sylvain ! Everything is working fine !")
41
 
42
  title="Stable Diffusion CPU"