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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
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,9 +17,6 @@ YOUR_TOKEN=MY_SECRET_TOKEN
17
 
18
  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
 
@@ -33,9 +30,17 @@ def resize(width,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")
41
  for i, image in enumerate(images_list["sample"]):
 
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
  source_img = gr.Image(source="upload", type="filepath", label="init_img")
21
  gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
22
 
 
30
 
31
 
32
  def infer(prompt, source_img):
33
+ if(source_img != None):
34
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
35
+ pipe.to(device)
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
+ else:
40
+ pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
41
+ pipe.to(device)
42
+ images_list = pipe([prompt] * 2)
43
+
44
  images = []
45
  safe_image = Image.open(r"unsafe.png")
46
  for i, image in enumerate(images_list["sample"]):