jiuface commited on
Commit
4ad7298
·
verified ·
1 Parent(s): 7bddac9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -29
app.py CHANGED
@@ -82,11 +82,7 @@ def generate_image(orginal_image, prompt, adapter_names, steps, seed, image_str
82
 
83
  with calculateDuration("Generating image"):
84
  # Generate image
85
- joint_attention_kwargs = {"scale": 1}
86
- if len(adapter_names) == 0:
87
- joint_attention_kwargs = None
88
- pipe.unload_lora_weights()
89
-
90
  if orginal_image:
91
  generated_image = img2img(
92
  prompt=prompt,
@@ -110,8 +106,7 @@ def generate_image(orginal_image, prompt, adapter_names, steps, seed, image_str
110
  generator=generator,
111
  joint_attention_kwargs=joint_attention_kwargs
112
  ).images[0]
113
- if len(adapter_names) > 0:
114
- pipe.unload_lora_weights()
115
  progress(99, "Generate image success!")
116
  return generated_image
117
 
@@ -171,10 +166,6 @@ def run_lora(prompt, image_url, lora_strings_json, image_strength, cfg_scale, s
171
  # Load LoRA weights
172
  gr.Info("Start to load LoRA ...")
173
 
174
- with calculateDuration("Unloading LoRA"):
175
- pipe.unload_lora_weights()
176
- img2img.unload_lora_weights()
177
-
178
  lora_configs = None
179
  adapter_names = []
180
 
@@ -193,25 +184,17 @@ def run_lora(prompt, image_url, lora_strings_json, image_strength, cfg_scale, s
193
  weights = lora_info.get("weights")
194
  adapter_name = lora_info.get("adapter_name")
195
  adapter_weight = lora_info.get("adapter_weight")
196
-
 
197
  if lora_repo and weights and adapter_name:
198
- retry_count = 3
199
- for attempt in range(retry_count):
200
- try:
201
- if img2img_model:
202
- img2img.load_lora_weights(lora_repo, weight_name=weights, adapter_name=adapter_name)
203
- else:
204
- pipe.load_lora_weights(lora_repo, weight_name=weights, adapter_name=adapter_name)
205
- adapter_names.append(adapter_name)
206
- adapter_weights.append(adapter_weight)
207
- break # Load successful, exit retry loop
208
- except ValueError as e:
209
- print(f"Attempt {attempt+1}/{retry_count} failed to load LoRA adapter: {e}")
210
- if attempt == retry_count - 1:
211
- print(f"Error loading LoRA adapter: {adapter_name} after {retry_count} attempts")
212
- else:
213
- time.sleep(1) # Wait before retrying
214
-
215
  # set lora weights
216
  if len(adapter_names) > 0:
217
  if img2img_model:
 
82
 
83
  with calculateDuration("Generating image"):
84
  # Generate image
85
+ joint_attention_kwargs = {"scale": 1}
 
 
 
 
86
  if orginal_image:
87
  generated_image = img2img(
88
  prompt=prompt,
 
106
  generator=generator,
107
  joint_attention_kwargs=joint_attention_kwargs
108
  ).images[0]
109
+
 
110
  progress(99, "Generate image success!")
111
  return generated_image
112
 
 
166
  # Load LoRA weights
167
  gr.Info("Start to load LoRA ...")
168
 
 
 
 
 
169
  lora_configs = None
170
  adapter_names = []
171
 
 
184
  weights = lora_info.get("weights")
185
  adapter_name = lora_info.get("adapter_name")
186
  adapter_weight = lora_info.get("adapter_weight")
187
+ adapter_names.append(adapter_name)
188
+ adapter_weights.append(adapter_weight)
189
  if lora_repo and weights and adapter_name:
190
+ try:
191
+ if img2img_model:
192
+ img2img.load_lora_weights(lora_repo, weight_name=weights, adapter_name=adapter_name)
193
+ else:
194
+ pipe.load_lora_weights(lora_repo, weight_name=weights, adapter_name=adapter_name)
195
+ except ValueError as e:
196
+ print(f"Attempt {attempt+1}/{retry_count} failed to load LoRA adapter: {e}")
197
+
 
 
 
 
 
 
 
 
 
198
  # set lora weights
199
  if len(adapter_names) > 0:
200
  if img2img_model: