Update app.py
Browse files
app.py
CHANGED
@@ -468,6 +468,7 @@ def generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress)
|
|
468 |
output_type="pil",
|
469 |
good_vae=good_vae,
|
470 |
):
|
|
|
471 |
yield img
|
472 |
|
473 |
@spaces.GPU(duration=75)
|
@@ -488,13 +489,15 @@ def run_lora(prompt, cfg_scale, steps, selected_indices, lora_scale_1, lora_scal
|
|
488 |
else:
|
489 |
appends.append(trigger_word)
|
490 |
prompt_mash = " ".join(prepends + [prompt] + appends)
|
491 |
-
print("Prompt Mash: ", prompt_mash)
|
|
|
492 |
# Unload previous LoRA weights
|
493 |
with calculateDuration("Unloading LoRA"):
|
494 |
pipe.unload_lora_weights()
|
495 |
pipe_i2i.unload_lora_weights()
|
496 |
|
497 |
print(pipe.get_active_adapters())
|
|
|
498 |
# Load LoRA weights with respective scales
|
499 |
lora_names = []
|
500 |
lora_weights = []
|
@@ -514,15 +517,15 @@ def run_lora(prompt, cfg_scale, steps, selected_indices, lora_scale_1, lora_scal
|
|
514 |
low_cpu_mem_usage=True,
|
515 |
adapter_name=lora_name
|
516 |
)
|
517 |
-
# if image_input is not None: pipe_i2i = pipe_to_use
|
518 |
-
# else: pipe = pipe_to_use
|
519 |
print("Loaded LoRAs:", lora_names)
|
520 |
print("Adapter weights:", lora_weights)
|
521 |
if image_input is not None:
|
522 |
pipe_i2i.set_adapters(lora_names, adapter_weights=lora_weights)
|
523 |
else:
|
524 |
pipe.set_adapters(lora_names, adapter_weights=lora_weights)
|
|
|
525 |
print(pipe.get_active_adapters())
|
|
|
526 |
# Set random seed for reproducibility
|
527 |
with calculateDuration("Randomizing seed"):
|
528 |
if randomize_seed:
|
@@ -530,20 +533,27 @@ def run_lora(prompt, cfg_scale, steps, selected_indices, lora_scale_1, lora_scal
|
|
530 |
print("Image Seed:", seed)
|
531 |
|
532 |
# Generate image
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
547 |
|
548 |
run_lora.zerogpu = True
|
549 |
|
|
|
468 |
output_type="pil",
|
469 |
good_vae=good_vae,
|
470 |
):
|
471 |
+
print("Image generated successfully.") # Debugging statement
|
472 |
yield img
|
473 |
|
474 |
@spaces.GPU(duration=75)
|
|
|
489 |
else:
|
490 |
appends.append(trigger_word)
|
491 |
prompt_mash = " ".join(prepends + [prompt] + appends)
|
492 |
+
print("Prompt Mash: ", prompt_mash) # Debugging statement
|
493 |
+
|
494 |
# Unload previous LoRA weights
|
495 |
with calculateDuration("Unloading LoRA"):
|
496 |
pipe.unload_lora_weights()
|
497 |
pipe_i2i.unload_lora_weights()
|
498 |
|
499 |
print(pipe.get_active_adapters())
|
500 |
+
|
501 |
# Load LoRA weights with respective scales
|
502 |
lora_names = []
|
503 |
lora_weights = []
|
|
|
517 |
low_cpu_mem_usage=True,
|
518 |
adapter_name=lora_name
|
519 |
)
|
|
|
|
|
520 |
print("Loaded LoRAs:", lora_names)
|
521 |
print("Adapter weights:", lora_weights)
|
522 |
if image_input is not None:
|
523 |
pipe_i2i.set_adapters(lora_names, adapter_weights=lora_weights)
|
524 |
else:
|
525 |
pipe.set_adapters(lora_names, adapter_weights=lora_weights)
|
526 |
+
|
527 |
print(pipe.get_active_adapters())
|
528 |
+
|
529 |
# Set random seed for reproducibility
|
530 |
with calculateDuration("Randomizing seed"):
|
531 |
if randomize_seed:
|
|
|
533 |
print("Image Seed:", seed)
|
534 |
|
535 |
# Generate image
|
536 |
+
try:
|
537 |
+
if image_input is not None:
|
538 |
+
#final_image = generate_image_to_image(prompt_mash, image_input, image_strength, steps, cfg_scale, width, height, seed)
|
539 |
+
yield final_image, seed, gr.update(visible=False)
|
540 |
+
else:
|
541 |
+
image_generator = generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress)
|
542 |
+
# Consume the generator to get the final image
|
543 |
+
final_image = None
|
544 |
+
step_counter = 0
|
545 |
+
for image in image_generator:
|
546 |
+
step_counter += 1
|
547 |
+
final_image = image
|
548 |
+
print(f"Yielding image {step_counter}/{steps}") # Debugging statement
|
549 |
+
progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
|
550 |
+
yield image, seed, gr.update(value=progress_bar, visible=True)
|
551 |
+
if final_image is None:
|
552 |
+
print("No final image generated.") # Debugging statement
|
553 |
+
yield final_image, seed, gr.update(value=progress_bar, visible=False)
|
554 |
+
except Exception as e:
|
555 |
+
print(f"Error during image generation: {e}") # Error handling
|
556 |
+
raise gr.Error("An error occurred during image generation.")
|
557 |
|
558 |
run_lora.zerogpu = True
|
559 |
|