ChenyangSi commited on
Commit
b107b62
1 Parent(s): a12399b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -55
app.py CHANGED
@@ -19,11 +19,18 @@ model_id = "CompVis/stable-diffusion-v1-4"
19
  # register_free_crossattn_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
20
  # # -------- freeu block registration
21
 
22
- def infer(prompt):
23
-
 
 
 
 
 
 
24
  print("Generating SD:")
25
  sd_image = pip_sd(prompt).images[0]
26
 
 
27
  print("Generating FreeU:")
28
  freeu_image = pip_freeu(prompt).images[0]
29
 
@@ -99,8 +106,21 @@ with block:
99
  with gr.Group():
100
  with gr.Row():
101
  sd_options = gr.Dropdown(['SD1.4', 'SD1.5', 'SD2.1'], value='SD1.4', label="SD options")
 
 
 
 
 
 
 
102
 
103
- with gr.Column():
 
 
 
 
 
 
104
  text = gr.Textbox(
105
  label="Enter your prompt",
106
  show_label=False,
@@ -114,7 +134,7 @@ with block:
114
  step=1,
115
  value=42)
116
 
117
-
118
  with gr.Group():
119
  with gr.Row():
120
  with gr.Accordion('FreeU Parameters: b', open=True):
@@ -138,9 +158,7 @@ with block:
138
  minimum=0,
139
  maximum=1,
140
  step=0.1,
141
- value=1)
142
-
143
-
144
 
145
  with gr.Row():
146
  with gr.Group():
@@ -159,56 +177,11 @@ with block:
159
  image_2_label = gr.Markdown("FreeU")
160
 
161
 
162
- # with gr.Column():
163
- # sd_options = gr.Dropdown(options, value='SD1.4', label="SD options")
164
- # model_id = "CompVis/stable-diffusion-v1-4"
165
- # with gr.Accordion('FreeU Parameters', open=False):
166
- # b1 = gr.Slider(label='b1: backbone factor of the first stage block of decoder',
167
- # minimum=1,
168
- # maximum=1.6,
169
- # step=0.1,
170
- # value=1)
171
- # b2 = gr.Slider(label='b2: backbone factor of the second stage block of decoder',
172
- # minimum=1,
173
- # maximum=1.6,
174
- # step=0.1,
175
- # value=1)
176
- # s1 = gr.Slider(label='s1: skip factor of the first stage block of decoder',
177
- # minimum=0,
178
- # maximum=1,
179
- # step=0.1,
180
- # value=1)
181
- # s2 = gr.Slider(label='s2: skip factor of the second stage block of decoder',
182
- # minimum=0,
183
- # maximum=1,
184
- # step=0.1,
185
- # value=1)
186
- # with gr.Group():
187
- # with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
188
- # with gr.Column():
189
- # text = gr.Textbox(
190
- # label="Enter your prompt",
191
- # show_label=False,
192
- # max_lines=1,
193
- # placeholder="Enter your prompt",
194
- # container=False,
195
- # )
196
- # btn = gr.Button("Generate image", scale=0)
197
-
198
- # with gr.Row():
199
- # with gr.Column(min_width=256) as c1:
200
- # image_1 = gr.Image(interactive=False)
201
- # image_1_label = gr.Markdown("SD")
202
- # with gr.Column(min_width=256) as c2:
203
- # image_2 = gr.Image(interactive=False)
204
- # image_2_label = gr.Markdown("FreeU")
205
-
206
-
207
- ex = gr.Examples(examples=examples, fn=infer, inputs=[text], outputs=[image_1, image_2], cache_examples=False)
208
  ex.dataset.headers = [""]
209
 
210
- text.submit(infer, inputs=[text], outputs=[image_1, image_2])
211
- btn.click(infer, inputs=[text], outputs=[image_1, image_2])
212
 
213
  block.launch()
214
  # block.queue(default_enabled=False).launch(share=False)
 
19
  # register_free_crossattn_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
20
  # # -------- freeu block registration
21
 
22
+ def infer(prompt, pip_sd, pip_freeu, seed, b1, b2, s1, s2):
23
+
24
+ # # -------- freeu block registration
25
+ # register_free_upblock2d(pip_freeu, b1=b1, b2=b2, s1=s1, s2=s1)
26
+ # register_free_crossattn_upblock2d(pip_freeu, b1=b1, b2=b2, s1=s1, s2=s1)
27
+ # # -------- freeu block registration
28
+
29
+ torch.manual_seed(seed)
30
  print("Generating SD:")
31
  sd_image = pip_sd(prompt).images[0]
32
 
33
+ torch.manual_seed(seed)
34
  print("Generating FreeU:")
35
  freeu_image = pip_freeu(prompt).images[0]
36
 
 
106
  with gr.Group():
107
  with gr.Row():
108
  sd_options = gr.Dropdown(['SD1.4', 'SD1.5', 'SD2.1'], value='SD1.4', label="SD options")
109
+
110
+ if sd_options == 'SD1.5':
111
+ model_id = "runwayml/stable-diffusion-v1-5"
112
+ elif sd_options == 'SD2.1':
113
+ model_id = "stabilityai/stable-diffusion-2-1"
114
+ else:
115
+ model_id = "CompVis/stable-diffusion-v1-4"
116
 
117
+ pip_sd = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
118
+ pip_sd = pip_sd.to("cuda")
119
+
120
+ pip_freeu = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
121
+ pip_freeu = pip_freeu.to("cuda")
122
+
123
+ with gr.Row():
124
  text = gr.Textbox(
125
  label="Enter your prompt",
126
  show_label=False,
 
134
  step=1,
135
  value=42)
136
 
137
+
138
  with gr.Group():
139
  with gr.Row():
140
  with gr.Accordion('FreeU Parameters: b', open=True):
 
158
  minimum=0,
159
  maximum=1,
160
  step=0.1,
161
+ value=1)
 
 
162
 
163
  with gr.Row():
164
  with gr.Group():
 
177
  image_2_label = gr.Markdown("FreeU")
178
 
179
 
180
+ ex = gr.Examples(examples=examples, fn=infer, inputs=[text, pip_sd, pip_freeu, seed, b1, b2, s1, s2], outputs=[image_1, image_2], cache_examples=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  ex.dataset.headers = [""]
182
 
183
+ text.submit(infer, inputs=[text, pip_sd, pip_freeu, seed, b1, b2, s1, s2], outputs=[image_1, image_2])
184
+ btn.click(infer, inputs=[text, pip_sd, pip_freeu, seed, b1, b2, s1, s2], outputs=[image_1, image_2])
185
 
186
  block.launch()
187
  # block.queue(default_enabled=False).launch(share=False)