fffiloni commited on
Commit
d02a25f
1 Parent(s): b328128

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -17,6 +17,12 @@ YOUR_TOKEN=MY_SECRET_TOKEN
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,16 +36,12 @@ def resize(height,img):
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")
 
17
 
18
  device="cpu"
19
 
20
+ prompt_pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
21
+ prompt_pipe.to(device)
22
+
23
+ img_pipe = StableDiffusionImg2ImgPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
24
+ img_pipe.to(device)
25
+
26
  source_img = gr.Image(source="upload", type="filepath", label="init_img")
27
  gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
28
 
 
36
 
37
 
38
  def infer(prompt, source_img):
39
+ if(source_img != None):
 
 
40
  init_image = resize(512,source_img)
41
  init_image.save('source.png')
42
+ images_list = img_pipe([prompt] * 2, init_image=init_image, strength=0.75)
43
+ else:
44
+ images_list = prompt_pipe([prompt] * 2)
 
 
45
 
46
  images = []
47
  safe_image = Image.open(r"unsafe.png")