linoyts HF Staff commited on
Commit
030cf22
·
verified ·
1 Parent(s): ad63290

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -5
app.py CHANGED
@@ -22,8 +22,8 @@ SINGLE_MODAL_VITAL_LAYERS = list(np.array([28, 53, 54, 56, 25]) - 19)
22
  pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev",
23
 
24
  torch_dtype=torch.bfloat16)
25
- pipe.load_lora_weights(hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8steps-lora.safetensors"), lora_scale=0.125)
26
- pipe.fuse_lora(lora_scale=0.125)
27
 
28
  #pipe.enable_lora()
29
  pipe.to("cuda")
@@ -83,10 +83,15 @@ def check_hyper_flux_lora(enable_hyper_flux):
83
  pipe.unfuse_lora()
84
  return 28, 28
85
 
 
 
 
86
  @spaces.GPU(duration=150)
87
  def invert_and_edit(image,
88
  source_prompt,
89
- edit_prompt,
 
 
90
  num_inversion_steps,
91
  num_inference_steps,
92
  seed,
@@ -115,6 +120,13 @@ def invert_and_edit(image,
115
  else:
116
  # move to gpu because of zero and gr.states
117
  inverted_latent_list = [tensor.to(DEVICE) for tensor in inverted_latent_list]
 
 
 
 
 
 
 
118
  output = pipe(
119
  [source_prompt, edit_prompt],
120
  height=1024,
@@ -125,8 +137,8 @@ def invert_and_edit(image,
125
  max_sequence_length=512,
126
  latents=inverted_latent_list[-1].tile(2, 1, 1),
127
  inverted_latent_list=inverted_latent_list,
128
- mm_copy_blocks=MULTIMODAL_VITAL_LAYERS,
129
- single_copy_blocks=SINGLE_MODAL_VITAL_LAYERS,
130
  ).images[1]
131
 
132
  # move back to cpu because of zero and gr.states
@@ -171,6 +183,19 @@ following the algorithm proposed in [*Stable Flow: Vital Layers for Training-Fre
171
  max_lines=1,
172
  placeholder="describe the edited output",
173
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  with gr.Row():
175
  enable_hyper_flux = gr.Checkbox(label="8-step LoRA", value=False, info="may reduce edit quality", visible=False)
176
 
@@ -237,6 +262,8 @@ following the algorithm proposed in [*Stable Flow: Vital Layers for Training-Fre
237
  input_image,
238
  source_prompt,
239
  edit_prompt,
 
 
240
  num_inversion_steps,
241
  num_inference_steps,
242
  seed,
 
22
  pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev",
23
 
24
  torch_dtype=torch.bfloat16)
25
+ # pipe.load_lora_weights(hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8steps-lora.safetensors"), lora_scale=0.125)
26
+ # pipe.fuse_lora(lora_scale=0.125)
27
 
28
  #pipe.enable_lora()
29
  pipe.to("cuda")
 
83
  pipe.unfuse_lora()
84
  return 28, 28
85
 
86
+ def convert_string_to_list(s):
87
+ return [int(x) for x in s.split(',') if x]
88
+
89
  @spaces.GPU(duration=150)
90
  def invert_and_edit(image,
91
  source_prompt,
92
+ edit_prompt,
93
+ multimodal_layers,
94
+ single_layers,
95
  num_inversion_steps,
96
  num_inference_steps,
97
  seed,
 
120
  else:
121
  # move to gpu because of zero and gr.states
122
  inverted_latent_list = [tensor.to(DEVICE) for tensor in inverted_latent_list]
123
+
124
+ try:
125
+ multimodal_layers = convert_string_to_list(multimodal_layers)
126
+ single_layers = convert_string_to_list(single_layers)
127
+ except:
128
+ multimodal_layers = MULTIMODAL_VITAL_LAYERS
129
+ single_layers = SINGLE_MODAL_VITAL_LAYERS
130
  output = pipe(
131
  [source_prompt, edit_prompt],
132
  height=1024,
 
137
  max_sequence_length=512,
138
  latents=inverted_latent_list[-1].tile(2, 1, 1),
139
  inverted_latent_list=inverted_latent_list,
140
+ mm_copy_blocks=multimodal_layers,
141
+ single_copy_blocks=single_layers,
142
  ).images[1]
143
 
144
  # move back to cpu because of zero and gr.states
 
183
  max_lines=1,
184
  placeholder="describe the edited output",
185
  )
186
+ with gr.Row():
187
+ multimodal_layers = gr.Text(
188
+ info = "the attention layers used for injection",
189
+ label="vital multimodal layers",
190
+ max_lines=1,
191
+ placeholder="0, 1, 17, 18",
192
+ )
193
+ single_layers = gr.Text(
194
+ info = "the attention layers used for injection",
195
+ label="vital single layers",
196
+ max_lines=1,
197
+ placeholder="9, 34, 35, 37, 6",
198
+ )
199
  with gr.Row():
200
  enable_hyper_flux = gr.Checkbox(label="8-step LoRA", value=False, info="may reduce edit quality", visible=False)
201
 
 
262
  input_image,
263
  source_prompt,
264
  edit_prompt,
265
+ multimodal_layers,
266
+ single_layers,
267
  num_inversion_steps,
268
  num_inference_steps,
269
  seed,