Spaces:
Sleeping
Sleeping
charbelgrower
commited on
Commit
·
0eec16e
1
Parent(s):
993a012
v0.018
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ with open('loras.json', 'r') as f:
|
|
25 |
|
26 |
# Initialize the base model
|
27 |
dtype = torch.bfloat16
|
28 |
-
device =
|
29 |
base_model = "black-forest-labs/FLUX.1-dev"
|
30 |
|
31 |
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
@@ -95,16 +95,49 @@ def update_selection(evt: gr.SelectData, selected_indices, loras_state, width, h
|
|
95 |
return gr.update(), "Select a LoRA 1", "Select a LoRA 2", "Select a LoRA 3", "Select a LoRA 4", "Select a LoRA 5", "Select a LoRA 6", selected_indices, 1.15, 1.15, 1.15, 1.15, 1.15, 1.15, width, height, None, None, None, None, None, None
|
96 |
|
97 |
# Initialize defaults
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
if selected_indices:
|
110 |
last_selected_lora = loras_state[selected_indices[-1]]
|
@@ -112,38 +145,196 @@ def update_selection(evt: gr.SelectData, selected_indices, loras_state, width, h
|
|
112 |
else:
|
113 |
new_placeholder = "Type a prompt after selecting a LoRA"
|
114 |
|
115 |
-
return
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
def randomize_loras(selected_indices, loras_state):
|
133 |
num_loras = min(6, len(loras_state))
|
134 |
selected_indices = random.sample(range(len(loras_state)), num_loras)
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
for idx, sel_idx in enumerate(selected_indices):
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
random_prompt = random.choice(prompt_values)
|
146 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
149 |
if custom_lora:
|
@@ -174,36 +365,19 @@ def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
|
174 |
gr.Warning("You can select up to 6 LoRAs, remove one to select a new one.")
|
175 |
|
176 |
# Update selected_info and images
|
177 |
-
|
178 |
-
|
179 |
-
lora_image = [None] * 6
|
180 |
-
|
181 |
-
for idx, sel_idx in enumerate(selected_indices):
|
182 |
-
if idx < 6:
|
183 |
-
lora = current_loras[sel_idx]
|
184 |
-
selected_info[idx] = f"### LoRA {idx+1} Selected: {lora['title']} ✨"
|
185 |
-
lora_image[idx] = lora['image'] if lora['image'] else None
|
186 |
-
|
187 |
-
print("Finished adding custom LoRA")
|
188 |
-
return (
|
189 |
-
current_loras,
|
190 |
-
gr.update(value=gallery_items),
|
191 |
-
*selected_info,
|
192 |
-
selected_indices,
|
193 |
-
*lora_scale,
|
194 |
-
*lora_image
|
195 |
-
)
|
196 |
except Exception as e:
|
197 |
print(e)
|
198 |
gr.Warning(str(e))
|
199 |
-
return current_loras, gr.update(),
|
200 |
else:
|
201 |
-
return current_loras, gr.update(),
|
202 |
|
203 |
def generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress):
|
204 |
print("Generating image...")
|
205 |
-
pipe.to(
|
206 |
-
generator = torch.Generator(device=
|
207 |
with calculateDuration("Generating image"):
|
208 |
# Generate image
|
209 |
for img in pipe.flux_pipe_call_that_returns_an_iterable_of_images(
|
@@ -220,8 +394,8 @@ def generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress)
|
|
220 |
yield img
|
221 |
|
222 |
def generate_image_to_image(prompt_mash, image_input_path, image_strength, steps, cfg_scale, width, height, seed):
|
223 |
-
pipe_i2i.to(
|
224 |
-
generator = torch.Generator(device=
|
225 |
image_input = load_image(image_input_path)
|
226 |
final_image = pipe_i2i(
|
227 |
prompt=prompt_mash,
|
@@ -238,7 +412,26 @@ def generate_image_to_image(prompt_mash, image_input_path, image_strength, steps
|
|
238 |
return final_image
|
239 |
|
240 |
@spaces.GPU(duration=75)
|
241 |
-
def run_lora(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
if not selected_indices:
|
243 |
raise gr.Error("You must select at least one LoRA before proceeding.")
|
244 |
|
@@ -265,7 +458,14 @@ def run_lora(prompt, image_input, image_strength, cfg_scale, steps, selected_ind
|
|
265 |
# Load LoRA weights with respective scales
|
266 |
lora_names = []
|
267 |
lora_weights = []
|
268 |
-
lora_scales = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
with calculateDuration("Loading LoRA weights"):
|
270 |
for idx, lora in enumerate(selected_loras):
|
271 |
if idx >= 6:
|
@@ -313,7 +513,7 @@ def run_lora(prompt, image_input, image_strength, cfg_scale, steps, selected_ind
|
|
313 |
yield final_image, seed, gr.update(value=progress_bar, visible=False)
|
314 |
|
315 |
run_lora.zerogpu = True
|
316 |
-
|
317 |
def get_huggingface_safetensors(link):
|
318 |
split_link = link.split("/")
|
319 |
if len(split_link) == 2:
|
|
|
25 |
|
26 |
# Initialize the base model
|
27 |
dtype = torch.bfloat16
|
28 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
29 |
base_model = "black-forest-labs/FLUX.1-dev"
|
30 |
|
31 |
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
|
|
95 |
return gr.update(), "Select a LoRA 1", "Select a LoRA 2", "Select a LoRA 3", "Select a LoRA 4", "Select a LoRA 5", "Select a LoRA 6", selected_indices, 1.15, 1.15, 1.15, 1.15, 1.15, 1.15, width, height, None, None, None, None, None, None
|
96 |
|
97 |
# Initialize defaults
|
98 |
+
selected_info_1 = "Select a LoRA 1"
|
99 |
+
selected_info_2 = "Select a LoRA 2"
|
100 |
+
selected_info_3 = "Select a LoRA 3"
|
101 |
+
selected_info_4 = "Select a LoRA 4"
|
102 |
+
selected_info_5 = "Select a LoRA 5"
|
103 |
+
selected_info_6 = "Select a LoRA 6"
|
104 |
+
lora_scale_1 = 1.15
|
105 |
+
lora_scale_2 = 1.15
|
106 |
+
lora_scale_3 = 1.15
|
107 |
+
lora_scale_4 = 1.15
|
108 |
+
lora_scale_5 = 1.15
|
109 |
+
lora_scale_6 = 1.15
|
110 |
+
lora_image_1 = None
|
111 |
+
lora_image_2 = None
|
112 |
+
lora_image_3 = None
|
113 |
+
lora_image_4 = None
|
114 |
+
lora_image_5 = None
|
115 |
+
lora_image_6 = None
|
116 |
+
|
117 |
+
if len(selected_indices) >= 1:
|
118 |
+
lora1 = loras_state[selected_indices[0]]
|
119 |
+
selected_info_1 = f"### LoRA 1 Selected: [{lora1['title']}](https://huggingface.co/{lora1['repo']}) ✨"
|
120 |
+
lora_image_1 = lora1['image']
|
121 |
+
if len(selected_indices) >= 2:
|
122 |
+
lora2 = loras_state[selected_indices[1]]
|
123 |
+
selected_info_2 = f"### LoRA 2 Selected: [{lora2['title']}](https://huggingface.co/{lora2['repo']}) ✨"
|
124 |
+
lora_image_2 = lora2['image']
|
125 |
+
if len(selected_indices) >= 3:
|
126 |
+
lora3 = loras_state[selected_indices[2]]
|
127 |
+
selected_info_3 = f"### LoRA 3 Selected: [{lora3['title']}](https://huggingface.co/{lora3['repo']}) ✨"
|
128 |
+
lora_image_3 = lora3['image']
|
129 |
+
if len(selected_indices) >= 4:
|
130 |
+
lora4 = loras_state[selected_indices[3]]
|
131 |
+
selected_info_4 = f"### LoRA 4 Selected: [{lora4['title']}](https://huggingface.co/{lora4['repo']}) ✨"
|
132 |
+
lora_image_4 = lora4['image']
|
133 |
+
if len(selected_indices) >= 5:
|
134 |
+
lora5 = loras_state[selected_indices[4]]
|
135 |
+
selected_info_5 = f"### LoRA 5 Selected: [{lora5['title']}](https://huggingface.co/{lora5['repo']}) ✨"
|
136 |
+
lora_image_5 = lora5['image']
|
137 |
+
if len(selected_indices) >= 6:
|
138 |
+
lora6 = loras_state[selected_indices[5]]
|
139 |
+
selected_info_6 = f"### LoRA 6 Selected: [{lora6['title']}](https://huggingface.co/{lora6['repo']}) ✨"
|
140 |
+
lora_image_6 = lora6['image']
|
141 |
|
142 |
if selected_indices:
|
143 |
last_selected_lora = loras_state[selected_indices[-1]]
|
|
|
145 |
else:
|
146 |
new_placeholder = "Type a prompt after selecting a LoRA"
|
147 |
|
148 |
+
return (
|
149 |
+
gr.update(placeholder=new_placeholder),
|
150 |
+
selected_info_1,
|
151 |
+
selected_info_2,
|
152 |
+
selected_info_3,
|
153 |
+
selected_info_4,
|
154 |
+
selected_info_5,
|
155 |
+
selected_info_6,
|
156 |
+
selected_indices,
|
157 |
+
lora_scale_1,
|
158 |
+
lora_scale_2,
|
159 |
+
lora_scale_3,
|
160 |
+
lora_scale_4,
|
161 |
+
lora_scale_5,
|
162 |
+
lora_scale_6,
|
163 |
+
width,
|
164 |
+
height,
|
165 |
+
lora_image_1,
|
166 |
+
lora_image_2,
|
167 |
+
lora_image_3,
|
168 |
+
lora_image_4,
|
169 |
+
lora_image_5,
|
170 |
+
lora_image_6
|
171 |
+
)
|
172 |
|
173 |
+
def remove_lora_1(selected_indices, loras_state):
|
174 |
+
if len(selected_indices) >= 1:
|
175 |
+
selected_indices.pop(0)
|
176 |
+
return update_selection_after_removal(selected_indices, loras_state)
|
177 |
+
|
178 |
+
def remove_lora_2(selected_indices, loras_state):
|
179 |
+
if len(selected_indices) >= 2:
|
180 |
+
selected_indices.pop(1)
|
181 |
+
return update_selection_after_removal(selected_indices, loras_state)
|
182 |
+
|
183 |
+
def remove_lora_3(selected_indices, loras_state):
|
184 |
+
if len(selected_indices) >= 3:
|
185 |
+
selected_indices.pop(2)
|
186 |
+
return update_selection_after_removal(selected_indices, loras_state)
|
187 |
+
|
188 |
+
def remove_lora_4(selected_indices, loras_state):
|
189 |
+
if len(selected_indices) >= 4:
|
190 |
+
selected_indices.pop(3)
|
191 |
+
return update_selection_after_removal(selected_indices, loras_state)
|
192 |
+
|
193 |
+
def remove_lora_5(selected_indices, loras_state):
|
194 |
+
if len(selected_indices) >= 5:
|
195 |
+
selected_indices.pop(4)
|
196 |
+
return update_selection_after_removal(selected_indices, loras_state)
|
197 |
+
|
198 |
+
def remove_lora_6(selected_indices, loras_state):
|
199 |
+
if len(selected_indices) >= 6:
|
200 |
+
selected_indices.pop(5)
|
201 |
+
return update_selection_after_removal(selected_indices, loras_state)
|
202 |
+
|
203 |
+
def update_selection_after_removal(selected_indices, loras_state):
|
204 |
+
# Reinitialize defaults
|
205 |
+
selected_info_1 = "Select a LoRA 1"
|
206 |
+
selected_info_2 = "Select a LoRA 2"
|
207 |
+
selected_info_3 = "Select a LoRA 3"
|
208 |
+
selected_info_4 = "Select a LoRA 4"
|
209 |
+
selected_info_5 = "Select a LoRA 5"
|
210 |
+
selected_info_6 = "Select a LoRA 6"
|
211 |
+
lora_scale_1 = 1.15
|
212 |
+
lora_scale_2 = 1.15
|
213 |
+
lora_scale_3 = 1.15
|
214 |
+
lora_scale_4 = 1.15
|
215 |
+
lora_scale_5 = 1.15
|
216 |
+
lora_scale_6 = 1.15
|
217 |
+
lora_image_1 = None
|
218 |
+
lora_image_2 = None
|
219 |
+
lora_image_3 = None
|
220 |
+
lora_image_4 = None
|
221 |
+
lora_image_5 = None
|
222 |
+
lora_image_6 = None
|
223 |
|
224 |
+
# Update selected LoRAs
|
225 |
+
if len(selected_indices) >= 1:
|
226 |
+
lora1 = loras_state[selected_indices[0]]
|
227 |
+
selected_info_1 = f"### LoRA 1 Selected: [{lora1['title']}]({lora1['repo']}) ✨"
|
228 |
+
lora_image_1 = lora1['image']
|
229 |
+
if len(selected_indices) >= 2:
|
230 |
+
lora2 = loras_state[selected_indices[1]]
|
231 |
+
selected_info_2 = f"### LoRA 2 Selected: [{lora2['title']}]({lora2['repo']}) ✨"
|
232 |
+
lora_image_2 = lora2['image']
|
233 |
+
if len(selected_indices) >= 3:
|
234 |
+
lora3 = loras_state[selected_indices[2]]
|
235 |
+
selected_info_3 = f"### LoRA 3 Selected: [{lora3['title']}]({lora3['repo']}) ✨"
|
236 |
+
lora_image_3 = lora3['image']
|
237 |
+
if len(selected_indices) >= 4:
|
238 |
+
lora4 = loras_state[selected_indices[3]]
|
239 |
+
selected_info_4 = f"### LoRA 4 Selected: [{lora4['title']}]({lora4['repo']}) ✨"
|
240 |
+
lora_image_4 = lora4['image']
|
241 |
+
if len(selected_indices) >= 5:
|
242 |
+
lora5 = loras_state[selected_indices[4]]
|
243 |
+
selected_info_5 = f"### LoRA 5 Selected: [{lora5['title']}]({lora5['repo']}) ✨"
|
244 |
+
lora_image_5 = lora5['image']
|
245 |
+
if len(selected_indices) >= 6:
|
246 |
+
lora6 = loras_state[selected_indices[5]]
|
247 |
+
selected_info_6 = f"### LoRA 6 Selected: [{lora6['title']}]({lora6['repo']}) ✨"
|
248 |
+
lora_image_6 = lora6['image']
|
249 |
+
|
250 |
+
return (
|
251 |
+
selected_info_1,
|
252 |
+
selected_info_2,
|
253 |
+
selected_info_3,
|
254 |
+
selected_info_4,
|
255 |
+
selected_info_5,
|
256 |
+
selected_info_6,
|
257 |
+
selected_indices,
|
258 |
+
lora_scale_1,
|
259 |
+
lora_scale_2,
|
260 |
+
lora_scale_3,
|
261 |
+
lora_scale_4,
|
262 |
+
lora_scale_5,
|
263 |
+
lora_scale_6,
|
264 |
+
lora_image_1,
|
265 |
+
lora_image_2,
|
266 |
+
lora_image_3,
|
267 |
+
lora_image_4,
|
268 |
+
lora_image_5,
|
269 |
+
lora_image_6
|
270 |
+
)
|
271 |
|
272 |
def randomize_loras(selected_indices, loras_state):
|
273 |
num_loras = min(6, len(loras_state))
|
274 |
selected_indices = random.sample(range(len(loras_state)), num_loras)
|
275 |
+
selected_info_1 = "Select a LoRA 1"
|
276 |
+
selected_info_2 = "Select a LoRA 2"
|
277 |
+
selected_info_3 = "Select a LoRA 3"
|
278 |
+
selected_info_4 = "Select a LoRA 4"
|
279 |
+
selected_info_5 = "Select a LoRA 5"
|
280 |
+
selected_info_6 = "Select a LoRA 6"
|
281 |
+
lora_scale_1 = 1.15
|
282 |
+
lora_scale_2 = 1.15
|
283 |
+
lora_scale_3 = 1.15
|
284 |
+
lora_scale_4 = 1.15
|
285 |
+
lora_scale_5 = 1.15
|
286 |
+
lora_scale_6 = 1.15
|
287 |
+
lora_image_1 = None
|
288 |
+
lora_image_2 = None
|
289 |
+
lora_image_3 = None
|
290 |
+
lora_image_4 = None
|
291 |
+
lora_image_5 = None
|
292 |
+
lora_image_6 = None
|
293 |
|
294 |
for idx, sel_idx in enumerate(selected_indices):
|
295 |
+
lora = loras_state[sel_idx]
|
296 |
+
if idx == 0:
|
297 |
+
selected_info_1 = f"### LoRA 1 Selected: [{lora['title']}](https://huggingface.co/{lora['repo']}) ✨"
|
298 |
+
lora_image_1 = lora['image']
|
299 |
+
elif idx == 1:
|
300 |
+
selected_info_2 = f"### LoRA 2 Selected: [{lora['title']}](https://huggingface.co/{lora['repo']}) ✨"
|
301 |
+
lora_image_2 = lora['image']
|
302 |
+
elif idx == 2:
|
303 |
+
selected_info_3 = f"### LoRA 3 Selected: [{lora['title']}](https://huggingface.co/{lora['repo']}) ✨"
|
304 |
+
lora_image_3 = lora['image']
|
305 |
+
elif idx == 3:
|
306 |
+
selected_info_4 = f"### LoRA 4 Selected: [{lora['title']}](https://huggingface.co/{lora['repo']}) ✨"
|
307 |
+
lora_image_4 = lora['image']
|
308 |
+
elif idx == 4:
|
309 |
+
selected_info_5 = f"### LoRA 5 Selected: [{lora['title']}](https://huggingface.co/{lora['repo']}) ✨"
|
310 |
+
lora_image_5 = lora['image']
|
311 |
+
elif idx == 5:
|
312 |
+
selected_info_6 = f"### LoRA 6 Selected: [{lora['title']}](https://huggingface.co/{lora['repo']}) ✨"
|
313 |
+
lora_image_6 = lora['image']
|
314 |
|
315 |
random_prompt = random.choice(prompt_values)
|
316 |
+
return (
|
317 |
+
selected_info_1,
|
318 |
+
selected_info_2,
|
319 |
+
selected_info_3,
|
320 |
+
selected_info_4,
|
321 |
+
selected_info_5,
|
322 |
+
selected_info_6,
|
323 |
+
selected_indices,
|
324 |
+
lora_scale_1,
|
325 |
+
lora_scale_2,
|
326 |
+
lora_scale_3,
|
327 |
+
lora_scale_4,
|
328 |
+
lora_scale_5,
|
329 |
+
lora_scale_6,
|
330 |
+
lora_image_1,
|
331 |
+
lora_image_2,
|
332 |
+
lora_image_3,
|
333 |
+
lora_image_4,
|
334 |
+
lora_image_5,
|
335 |
+
lora_image_6,
|
336 |
+
random_prompt
|
337 |
+
)
|
338 |
|
339 |
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
340 |
if custom_lora:
|
|
|
365 |
gr.Warning("You can select up to 6 LoRAs, remove one to select a new one.")
|
366 |
|
367 |
# Update selected_info and images
|
368 |
+
return update_selection_after_removal(selected_indices, current_loras)[:20] + (current_loras, gr.update(value=gallery_items))
|
369 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
except Exception as e:
|
371 |
print(e)
|
372 |
gr.Warning(str(e))
|
373 |
+
return current_loras, gr.update(), "Select a LoRA 1", "Select a LoRA 2", "Select a LoRA 3", "Select a LoRA 4", "Select a LoRA 5", "Select a LoRA 6", selected_indices, 1.15, 1.15, 1.15, 1.15, 1.15, 1.15, None, None, None, None, None, None
|
374 |
else:
|
375 |
+
return current_loras, gr.update(), "Select a LoRA 1", "Select a LoRA 2", "Select a LoRA 3", "Select a LoRA 4", "Select a LoRA 5", "Select a LoRA 6", selected_indices, 1.15, 1.15, 1.15, 1.15, 1.15, 1.15, None, None, None, None, None, None
|
376 |
|
377 |
def generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress):
|
378 |
print("Generating image...")
|
379 |
+
pipe.to("cuda")
|
380 |
+
generator = torch.Generator(device="cuda").manual_seed(seed)
|
381 |
with calculateDuration("Generating image"):
|
382 |
# Generate image
|
383 |
for img in pipe.flux_pipe_call_that_returns_an_iterable_of_images(
|
|
|
394 |
yield img
|
395 |
|
396 |
def generate_image_to_image(prompt_mash, image_input_path, image_strength, steps, cfg_scale, width, height, seed):
|
397 |
+
pipe_i2i.to("cuda")
|
398 |
+
generator = torch.Generator(device="cuda").manual_seed(seed)
|
399 |
image_input = load_image(image_input_path)
|
400 |
final_image = pipe_i2i(
|
401 |
prompt=prompt_mash,
|
|
|
412 |
return final_image
|
413 |
|
414 |
@spaces.GPU(duration=75)
|
415 |
+
def run_lora(
|
416 |
+
prompt,
|
417 |
+
image_input,
|
418 |
+
image_strength,
|
419 |
+
cfg_scale,
|
420 |
+
steps,
|
421 |
+
selected_indices,
|
422 |
+
lora_scale_1,
|
423 |
+
lora_scale_2,
|
424 |
+
lora_scale_3,
|
425 |
+
lora_scale_4,
|
426 |
+
lora_scale_5,
|
427 |
+
lora_scale_6,
|
428 |
+
randomize_seed,
|
429 |
+
seed,
|
430 |
+
width,
|
431 |
+
height,
|
432 |
+
loras_state,
|
433 |
+
progress=gr.Progress(track_tqdm=True)
|
434 |
+
):
|
435 |
if not selected_indices:
|
436 |
raise gr.Error("You must select at least one LoRA before proceeding.")
|
437 |
|
|
|
458 |
# Load LoRA weights with respective scales
|
459 |
lora_names = []
|
460 |
lora_weights = []
|
461 |
+
lora_scales = [
|
462 |
+
lora_scale_1,
|
463 |
+
lora_scale_2,
|
464 |
+
lora_scale_3,
|
465 |
+
lora_scale_4,
|
466 |
+
lora_scale_5,
|
467 |
+
lora_scale_6
|
468 |
+
]
|
469 |
with calculateDuration("Loading LoRA weights"):
|
470 |
for idx, lora in enumerate(selected_loras):
|
471 |
if idx >= 6:
|
|
|
513 |
yield final_image, seed, gr.update(value=progress_bar, visible=False)
|
514 |
|
515 |
run_lora.zerogpu = True
|
516 |
+
@spaces.GPU
|
517 |
def get_huggingface_safetensors(link):
|
518 |
split_link = link.split("/")
|
519 |
if len(split_link) == 2:
|