ChenyangSi commited on
Commit
7d24c56
·
1 Parent(s): bd26015

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -26,10 +26,19 @@ model_id = "CompVis/stable-diffusion-v1-4"
26
  # register_free_crossattn_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
27
  # # -------- freeu block registration
28
 
29
- pip = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
30
- pip = pip.to("cuda")
 
 
 
 
 
 
 
 
 
31
 
32
- def infer(prompt, sd_model, seed, b1, b2, s1, s2):
33
 
34
  # pip = StableDiffusionPipeline.from_pretrained(model, torch_dtype=torch.float16)
35
  # pip = pip.to("cuda")
@@ -40,14 +49,14 @@ def infer(prompt, sd_model, seed, b1, b2, s1, s2):
40
 
41
  torch.manual_seed(seed)
42
  print("Generating SD:")
43
- sd_image = pip(prompt).images[0]
44
 
45
  # register_free_upblock2d(pip, b1=b1, b2=b2, s1=s1, s2=s1)
46
  # register_free_crossattn_upblock2d(pip, b1=b1, b2=b2, s1=s1, s2=s1)
47
 
48
  torch.manual_seed(seed)
49
  print("Generating FreeU:")
50
- freeu_image = pip(prompt).images[0]
51
 
52
  # First SD, then freeu
53
  images = [sd_image, freeu_image]
@@ -123,11 +132,11 @@ with block:
123
  sd_options = gr.Dropdown(["SD1.4", "SD1.5", "SD2.1"], label="SD options")
124
 
125
  if sd_options == 'SD1.5':
126
- sd_model = 1.5
127
  elif sd_options == 'SD2.1':
128
- sd_model = 2.1
129
  else:
130
- sd_model = 1.4
131
 
132
  # pip = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
133
  # pip = pip.to("cuda")
@@ -179,23 +188,23 @@ with block:
179
  with gr.Group():
180
  # btn = gr.Button("Generate image", scale=0)
181
  with gr.Row():
182
- with gr.Column(min_width=256) as c1:
183
  image_1 = gr.Image(interactive=False)
184
  image_1_label = gr.Markdown("SD")
185
 
186
  with gr.Group():
187
  # btn = gr.Button("Generate image", scale=0)
188
  with gr.Row():
189
- with gr.Column(min_width=256) as c2:
190
  image_2 = gr.Image(interactive=False)
191
  image_2_label = gr.Markdown("FreeU")
192
 
193
 
194
- ex = gr.Examples(examples=examples, fn=infer, inputs=[text, sd_model, seed, b1, b2, s1, s2], outputs=[image_1, image_2], cache_examples=False)
195
  ex.dataset.headers = [""]
196
 
197
- text.submit(infer, inputs=[text, sd_model, seed, b1, b2, s1, s2], outputs=[image_1, image_2])
198
- btn.click(infer, inputs=[text, sd_model, seed, b1, b2, s1, s2], outputs=[image_1, image_2])
199
 
200
  block.launch()
201
  # block.queue(default_enabled=False).launch(share=False)
 
26
  # register_free_crossattn_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
27
  # # -------- freeu block registration
28
 
29
+ model_id = "CompVis/stable-diffusion-v1-4"
30
+ pip_1_4 = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
31
+ pip_1_4 = pip_1_4.to("cuda")
32
+
33
+ # model_id = "runwayml/stable-diffusion-v1-5"
34
+ # pip_1_5 = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
35
+ # pip_1_5 = pip_1_5.to("cuda")
36
+
37
+ # model_id = "stabilityai/stable-diffusion-2-1"
38
+ # pip_2_1 = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
39
+ # pip_2_1 = pip_2_1.to("cuda")
40
 
41
+ def infer(prompt, sd, seed, b1, b2, s1, s2):
42
 
43
  # pip = StableDiffusionPipeline.from_pretrained(model, torch_dtype=torch.float16)
44
  # pip = pip.to("cuda")
 
49
 
50
  torch.manual_seed(seed)
51
  print("Generating SD:")
52
+ sd_image = pip_1_4(prompt).images[0]
53
 
54
  # register_free_upblock2d(pip, b1=b1, b2=b2, s1=s1, s2=s1)
55
  # register_free_crossattn_upblock2d(pip, b1=b1, b2=b2, s1=s1, s2=s1)
56
 
57
  torch.manual_seed(seed)
58
  print("Generating FreeU:")
59
+ freeu_image = pip_1_4(prompt).images[0]
60
 
61
  # First SD, then freeu
62
  images = [sd_image, freeu_image]
 
132
  sd_options = gr.Dropdown(["SD1.4", "SD1.5", "SD2.1"], label="SD options")
133
 
134
  if sd_options == 'SD1.5':
135
+ sd = 1.5
136
  elif sd_options == 'SD2.1':
137
+ sd = 2.1
138
  else:
139
+ sd = 1.4
140
 
141
  # pip = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
142
  # pip = pip.to("cuda")
 
188
  with gr.Group():
189
  # btn = gr.Button("Generate image", scale=0)
190
  with gr.Row():
191
+ with gr.Column() as c1:
192
  image_1 = gr.Image(interactive=False)
193
  image_1_label = gr.Markdown("SD")
194
 
195
  with gr.Group():
196
  # btn = gr.Button("Generate image", scale=0)
197
  with gr.Row():
198
+ with gr.Column() as c2:
199
  image_2 = gr.Image(interactive=False)
200
  image_2_label = gr.Markdown("FreeU")
201
 
202
 
203
+ ex = gr.Examples(examples=examples, fn=infer, inputs=[text, sd, seed, b1, b2, s1, s2], outputs=[image_1, image_2], cache_examples=False)
204
  ex.dataset.headers = [""]
205
 
206
+ text.submit(infer, inputs=[text, sd, seed, b1, b2, s1, s2], outputs=[image_1, image_2])
207
+ btn.click(infer, inputs=[text, sd, seed, b1, b2, s1, s2], outputs=[image_1, image_2])
208
 
209
  block.launch()
210
  # block.queue(default_enabled=False).launch(share=False)