ChenyangSi commited on
Commit
62013d0
1 Parent(s): ea827c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -23
app.py CHANGED
@@ -13,10 +13,20 @@ import torch
13
  from free_lunch_utils import register_free_upblock2d, register_free_crossattn_upblock2d
14
 
15
 
16
- def infer(prompt, pip_sd, pip_freeu):
17
-
 
 
18
 
 
 
 
 
 
 
19
 
 
 
20
  print("Generating SD:")
21
  sd_image = pip_sd(prompt).images[0]
22
 
@@ -105,26 +115,25 @@ with block:
105
  )
106
  btn = gr.Button("Generate image", scale=0)
107
 
108
- # sd_options = gr.Dropdown(options, label="SD options")
109
- sd_options = gr.Dropdown(options, value='SD1.4', label="SD options")
110
- model_id = "CompVis/stable-diffusion-v1-4"
111
 
112
- if sd_options == 'SD1.4':
113
- model_id = "CompVis/stable-diffusion-v1-4"
114
- elif sd_options == 'SD1.5':
115
- model_id = "runwayml/stable-diffusion-v1-5"
116
- elif sd_options == 'SD2.1':
117
- model_id = "stabilityai/stable-diffusion-2-1"
118
 
119
- pip_sd = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
120
- pip_sd = pip_sd.to("cuda")
121
-
122
- pip_freeu = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
123
- pip_freeu = pip_freeu.to("cuda")
124
- # -------- freeu block registration
125
- register_free_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
126
- register_free_crossattn_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
127
- # -------- freeu block registration
128
 
129
  with gr.Accordion('FreeU Parameters', open=False):
130
 
@@ -158,11 +167,11 @@ with block:
158
  image_2_label = gr.Markdown("FreeU")
159
 
160
 
161
- ex = gr.Examples(examples=examples, fn=infer, inputs=[text, pip_sd, pip_freeu], outputs=[image_1, image_2], cache_examples=False)
162
  ex.dataset.headers = [""]
163
 
164
- text.submit(infer, inputs=[text, pip_sd, pip_freeu], outputs=[image_1, image_2])
165
- btn.click(infer, inputs=[text, pip_sd, pip_freeu], outputs=[image_1, image_2])
166
 
167
  block.launch()
168
  # block.queue(default_enabled=False).launch(share=False)
 
13
  from free_lunch_utils import register_free_upblock2d, register_free_crossattn_upblock2d
14
 
15
 
16
+ model_id = "CompVis/stable-diffusion-v1-4"
17
+
18
+ pip_sd = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
19
+ pip_sd = pip_sd.to("cuda")
20
 
21
+ pip_freeu = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
22
+ pip_freeu = pip_freeu.to("cuda")
23
+ # -------- freeu block registration
24
+ register_free_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
25
+ register_free_crossattn_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
26
+ # -------- freeu block registration
27
 
28
+ def infer(prompt):
29
+
30
  print("Generating SD:")
31
  sd_image = pip_sd(prompt).images[0]
32
 
 
115
  )
116
  btn = gr.Button("Generate image", scale=0)
117
 
118
+ # sd_options = gr.Dropdown(options, value='SD1.4', label="SD options")
119
+ # model_id = "CompVis/stable-diffusion-v1-4"
 
120
 
121
+ # if sd_options == 'SD1.4':
122
+ # model_id = "CompVis/stable-diffusion-v1-4"
123
+ # elif sd_options == 'SD1.5':
124
+ # model_id = "runwayml/stable-diffusion-v1-5"
125
+ # elif sd_options == 'SD2.1':
126
+ # model_id = "stabilityai/stable-diffusion-2-1"
127
 
128
+ # pip_sd = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
129
+ # pip_sd = pip_sd.to("cuda")
130
+
131
+ # pip_freeu = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
132
+ # pip_freeu = pip_freeu.to("cuda")
133
+ # # -------- freeu block registration
134
+ # register_free_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
135
+ # register_free_crossattn_upblock2d(pip_freeu, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
136
+ # # -------- freeu block registration
137
 
138
  with gr.Accordion('FreeU Parameters', open=False):
139
 
 
167
  image_2_label = gr.Markdown("FreeU")
168
 
169
 
170
+ ex = gr.Examples(examples=examples, fn=infer, inputs=[text], outputs=[image_1, image_2], cache_examples=False)
171
  ex.dataset.headers = [""]
172
 
173
+ text.submit(infer, inputs=[text], outputs=[image_1, image_2])
174
+ btn.click(infer, inputs=[text], outputs=[image_1, image_2])
175
 
176
  block.launch()
177
  # block.queue(default_enabled=False).launch(share=False)