ChenyangSi commited on
Commit
d8370d3
·
1 Parent(s): 6cae0a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -12,26 +12,11 @@ from muse import PipelineMuse
12
  from diffusers import AutoPipelineForText2Image, UniPCMultistepScheduler
13
 
14
 
15
- if sd_options == 'SD1.4':
16
- model_id = "CompVis/stable-diffusion-v1-4"
17
- elif sd_options == 'SD1.5':
18
- model_id = "runwayml/stable-diffusion-v1-5"
19
- elif sd_options == 'SD2.1':
20
- model_id = "stabilityai/stable-diffusion-2-1"
21
-
22
- pip_sd = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
23
- pip_sd = pip_sd.to("cuda")
24
-
25
 
26
- pip_freeu = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
27
- pip_freeu = pip_freeu.to("cuda")
28
- # -------- freeu block registration
29
- register_free_upblock2d(pipe, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
30
- register_free_crossattn_upblock2d(pipe, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
31
- # -------- freeu block registration
32
 
 
 
33
 
34
- def infer(prompt):
35
 
36
  print("Generating SD:")
37
  sd_image = pip_sd(prompt).images[0]
@@ -122,6 +107,23 @@ with block:
122
 
123
  with gr.Accordion('FreeU Parameters', open=False):
124
  sd_options = gr.Dropdown(options, label="SD options")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  b1 = gr.Slider(label='b1: backbone factor of the first stage block of decoder',
127
  minimum=1,
@@ -156,7 +158,7 @@ with block:
156
  ex = gr.Examples(examples=examples, fn=infer, inputs=[text], outputs=[image_1, image_2], cache_examples=False)
157
  ex.dataset.headers = [""]
158
 
159
- text.submit(infer, inputs=[text], outputs=[image_1, image_2])
160
- btn.click(infer, inputs=[text], outputs=[image_1, image_2])
161
 
162
  block.launch()
 
12
  from diffusers import AutoPipelineForText2Image, UniPCMultistepScheduler
13
 
14
 
 
 
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
 
16
 
17
+ def infer(prompt, pip_sd, pip_freeu):
18
+
19
 
 
20
 
21
  print("Generating SD:")
22
  sd_image = pip_sd(prompt).images[0]
 
107
 
108
  with gr.Accordion('FreeU Parameters', open=False):
109
  sd_options = gr.Dropdown(options, label="SD options")
110
+ if sd_options == 'SD1.4':
111
+ model_id = "CompVis/stable-diffusion-v1-4"
112
+ elif sd_options == 'SD1.5':
113
+ model_id = "runwayml/stable-diffusion-v1-5"
114
+ elif sd_options == 'SD2.1':
115
+ model_id = "stabilityai/stable-diffusion-2-1"
116
+
117
+ pip_sd = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
118
+ pip_sd = pip_sd.to("cuda")
119
+
120
+
121
+ pip_freeu = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
122
+ pip_freeu = pip_freeu.to("cuda")
123
+ # -------- freeu block registration
124
+ register_free_upblock2d(pipe, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
125
+ register_free_crossattn_upblock2d(pipe, b1=1.2, b2=1.4, s1=0.9, s2=0.2)
126
+ # -------- freeu block registration
127
 
128
  b1 = gr.Slider(label='b1: backbone factor of the first stage block of decoder',
129
  minimum=1,
 
158
  ex = gr.Examples(examples=examples, fn=infer, inputs=[text], outputs=[image_1, image_2], cache_examples=False)
159
  ex.dataset.headers = [""]
160
 
161
+ text.submit(infer, inputs=[text, pip_sd, pip_freeu], outputs=[image_1, image_2])
162
+ btn.click(infer, inputs=[text, pip_sd, pip_freeu], outputs=[image_1, image_2])
163
 
164
  block.launch()