Update app.py
Browse files
app.py
CHANGED
|
@@ -451,7 +451,7 @@ def generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress)
|
|
| 451 |
return img
|
| 452 |
|
| 453 |
@spaces.GPU(duration=75)
|
| 454 |
-
def run_lora(prompt, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, randomize_seed, seed, width, height, loras_state, progress=gr.Progress(track_tqdm=True)):
|
| 455 |
if not selected_indices:
|
| 456 |
raise gr.Error("You must select at least one LoRA before proceeding.")
|
| 457 |
|
|
@@ -469,51 +469,40 @@ def run_lora(prompt, cfg_scale, steps, selected_indices, lora_scale_1, lora_scal
|
|
| 469 |
appends.append(trigger_word)
|
| 470 |
prompt_mash = " ".join(prepends + [prompt] + appends)
|
| 471 |
print("Prompt Mash: ", prompt_mash)
|
| 472 |
-
|
| 473 |
# Unload previous LoRA weights
|
| 474 |
with calculateDuration("Unloading LoRA"):
|
| 475 |
pipe.unload_lora_weights()
|
| 476 |
|
| 477 |
-
|
| 478 |
-
print(pipe.get_active_adapters())
|
| 479 |
-
|
| 480 |
lora_names = []
|
| 481 |
lora_weights = []
|
| 482 |
with calculateDuration("Loading LoRA weights"):
|
| 483 |
for idx, lora in enumerate(selected_loras):
|
| 484 |
lora_name = f"lora_{idx}"
|
| 485 |
lora_names.append(lora_name)
|
| 486 |
-
print(f"Lora Name: {lora_name}")
|
| 487 |
lora_weights.append(lora_scale_1 if idx == 0 else lora_scale_2)
|
| 488 |
-
lora_path = lora['repo']
|
| 489 |
-
weight_name = lora.get("weights")
|
| 490 |
-
print(f"Lora Path: {lora_path}")
|
| 491 |
pipe.load_lora_weights(
|
| 492 |
-
|
| 493 |
-
weight_name=
|
| 494 |
low_cpu_mem_usage=True,
|
| 495 |
-
adapter_name=lora_name
|
| 496 |
)
|
| 497 |
-
|
| 498 |
-
print("Loaded LoRAs:", lora_names)
|
| 499 |
-
print("Adapter weights:", lora_weights)
|
| 500 |
-
|
| 501 |
pipe.set_adapters(lora_names, adapter_weights=lora_weights)
|
| 502 |
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
|
| 508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 509 |
|
| 510 |
-
step_counter = 0
|
| 511 |
-
for image in image_generator:
|
| 512 |
-
step_counter += 1
|
| 513 |
-
final_image = image
|
| 514 |
-
progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
|
| 515 |
-
yield image, seed, gr.update(value=progress_bar, visible=True)
|
| 516 |
-
|
| 517 |
run_lora.zerogpu = True
|
| 518 |
|
| 519 |
def get_huggingface_safetensors(link):
|
|
|
|
| 451 |
return img
|
| 452 |
|
| 453 |
@spaces.GPU(duration=75)
|
| 454 |
+
def run_lora(prompt, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, lora_scale_4, randomize_seed, seed, width, height, loras_state, progress=gr.Progress(track_tqdm=True)):
|
| 455 |
if not selected_indices:
|
| 456 |
raise gr.Error("You must select at least one LoRA before proceeding.")
|
| 457 |
|
|
|
|
| 469 |
appends.append(trigger_word)
|
| 470 |
prompt_mash = " ".join(prepends + [prompt] + appends)
|
| 471 |
print("Prompt Mash: ", prompt_mash)
|
| 472 |
+
|
| 473 |
# Unload previous LoRA weights
|
| 474 |
with calculateDuration("Unloading LoRA"):
|
| 475 |
pipe.unload_lora_weights()
|
| 476 |
|
| 477 |
+
# Load LoRA weights
|
|
|
|
|
|
|
| 478 |
lora_names = []
|
| 479 |
lora_weights = []
|
| 480 |
with calculateDuration("Loading LoRA weights"):
|
| 481 |
for idx, lora in enumerate(selected_loras):
|
| 482 |
lora_name = f"lora_{idx}"
|
| 483 |
lora_names.append(lora_name)
|
|
|
|
| 484 |
lora_weights.append(lora_scale_1 if idx == 0 else lora_scale_2)
|
|
|
|
|
|
|
|
|
|
| 485 |
pipe.load_lora_weights(
|
| 486 |
+
lora['repo'],
|
| 487 |
+
weight_name=lora.get("weights"),
|
| 488 |
low_cpu_mem_usage=True,
|
| 489 |
+
adapter_name=lora_name,
|
| 490 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
pipe.set_adapters(lora_names, adapter_weights=lora_weights)
|
| 492 |
|
| 493 |
+
# Set random seed if required
|
| 494 |
+
if randomize_seed:
|
| 495 |
+
seed = random.randint(0, MAX_SEED)
|
|
|
|
| 496 |
|
| 497 |
+
# Generate image
|
| 498 |
+
image_generator = generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress)
|
| 499 |
+
step_counter = 0
|
| 500 |
+
|
| 501 |
+
for image, seed, progress_update in image_generator:
|
| 502 |
+
step_counter += 1
|
| 503 |
+
progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
|
| 504 |
+
yield image, seed, gr.update(value=progress_bar, visible=True)
|
| 505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
run_lora.zerogpu = True
|
| 507 |
|
| 508 |
def get_huggingface_safetensors(link):
|