Update app.py
Browse files
app.py
CHANGED
|
@@ -483,10 +483,19 @@ def run_lora(prompt, cfg_scale, steps, selected_info_1, selected_info_2, selecte
|
|
| 483 |
prompt_mash = " ".join(prepends + [prompt] + appends)
|
| 484 |
print("Prompt Mash: ", prompt_mash) # Debugging statement
|
| 485 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
# Unload previous LoRA weights
|
| 487 |
with calculateDuration("Unloading LoRA"):
|
| 488 |
pipe.unload_lora_weights()
|
| 489 |
-
## pipe_i2i.unload_lora_weights()
|
| 490 |
print("Active adapters before loading new LoRAs:", pipe.get_active_adapters())
|
| 491 |
|
| 492 |
# Load LoRA weights with respective scales
|
|
@@ -503,62 +512,7 @@ def run_lora(prompt, cfg_scale, steps, selected_info_1, selected_info_2, selecte
|
|
| 503 |
lora_path = lora['repo']
|
| 504 |
weight_name = lora.get("weights")
|
| 505 |
print(f"Lora Path: {lora_path}")
|
| 506 |
-
pipe_to_use = pipe_i2i if
|
| 507 |
-
pipe_to_use.load_lora_weights(
|
| 508 |
-
lora_path,
|
| 509 |
-
weight_name=weight_name if weight_name else None,
|
| 510 |
-
low_cpu_mem_usage=True,
|
| 511 |
-
adapter_name=lora_name
|
| 512 |
-
)
|
| 513 |
-
print("Loaded LoRAs:", lora_names)
|
| 514 |
-
print("Adapter weights:", lora_weights)
|
| 515 |
-
## if image_input is not None:
|
| 516 |
-
## pipe_i2i.set_adapters(lora_names, adapter_weights=lora_weights)
|
| 517 |
-
## else:
|
| 518 |
-
## pipe.set_adapters(lora_names, adapter_weights=lora_weights)
|
| 519 |
-
|
| 520 |
-
## print("Active adapters after loading new LoRAs:", pipe.get_active_adapters())
|
| 521 |
-
|
| 522 |
-
# Set random seed for reproducibility
|
| 523 |
-
with calculateDuration("Randomizing seed"):
|
| 524 |
-
if randomize_seed:
|
| 525 |
-
seed = random.randint(0, MAX_SEED)
|
| 526 |
-
print("Image Seed:", seed)
|
| 527 |
-
|
| 528 |
-
# Generate image
|
| 529 |
-
try:
|
| 530 |
-
if image_input is not None:
|
| 531 |
-
final_image = generate_image_to_image(prompt_mash, image_input, image_strength, steps, cfg_scale, width, height, seed)
|
| 532 |
-
print("Debug: generate_image_to_image output type:", type(final_image)) # Debugging
|
| 533 |
-
print("Debug: generate_image_to_image output value:", final_image) # Debugging
|
| 534 |
-
yield final_image, seed, gr.update(visible=False)
|
| 535 |
-
else:
|
| 536 |
-
image_generator = generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress)
|
| 537 |
-
# Consume the generator to get the final image
|
| 538 |
-
final_image = None
|
| 539 |
-
step_counter = 0
|
| 540 |
-
for image in image_generator:
|
| 541 |
-
print("Debug: generate_image yielded type:", type(image)) # Debugging
|
| 542 |
-
print("Debug: generate_image yielded value:", image) # Debugging
|
| 543 |
-
step_counter += 1
|
| 544 |
-
final_image = image
|
| 545 |
-
print(f"Yielding image {step_counter}/{steps}") # Debugging statement
|
| 546 |
-
progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
|
| 547 |
-
yield image, seed, gr.update(value=progress_bar, visible=True)
|
| 548 |
-
if final_image is None:
|
| 549 |
-
print("No final image generated.") # Debugging statement
|
| 550 |
-
else:
|
| 551 |
-
print("Debug: final_image type:", type(final_image)) # Debugging
|
| 552 |
-
print("Debug: final_image value:", final_image) # Debugging
|
| 553 |
-
|
| 554 |
-
yield final_image, seed, gr.update(value=progress_bar, visible=False)
|
| 555 |
-
##
|
| 556 |
-
yield None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None # Placeholder for missing outputs
|
| 557 |
-
except Exception as e:
|
| 558 |
-
print(f"Error during image generation: {e}") # Error handling
|
| 559 |
-
raise gr.Error("An error occurred during image generation.")
|
| 560 |
-
|
| 561 |
-
run_lora.zerogpu = True
|
| 562 |
|
| 563 |
def get_huggingface_safetensors(link):
|
| 564 |
split_link = link.split("/")
|
|
|
|
| 483 |
prompt_mash = " ".join(prepends + [prompt] + appends)
|
| 484 |
print("Prompt Mash: ", prompt_mash) # Debugging statement
|
| 485 |
|
| 486 |
+
# Ensure valid width and height values
|
| 487 |
+
if width is None:
|
| 488 |
+
width = 1024 # Default value
|
| 489 |
+
if height is None:
|
| 490 |
+
height = 1024 # Default value
|
| 491 |
+
|
| 492 |
+
# Set seed value
|
| 493 |
+
if seed is None or randomize_seed:
|
| 494 |
+
seed = random.randint(0, MAX_SEED)
|
| 495 |
+
|
| 496 |
# Unload previous LoRA weights
|
| 497 |
with calculateDuration("Unloading LoRA"):
|
| 498 |
pipe.unload_lora_weights()
|
|
|
|
| 499 |
print("Active adapters before loading new LoRAs:", pipe.get_active_adapters())
|
| 500 |
|
| 501 |
# Load LoRA weights with respective scales
|
|
|
|
| 512 |
lora_path = lora['repo']
|
| 513 |
weight_name = lora.get("weights")
|
| 514 |
print(f"Lora Path: {lora_path}")
|
| 515 |
+
pipe_to_use = pipe_i2i if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
|
| 517 |
def get_huggingface_safetensors(link):
|
| 518 |
split_link = link.split("/")
|