Fix static output issue with LoRA loading and error handling
Browse files- Fix LoRA loading by properly unloading existing LoRAs first
- Add error handling for generation with fallback to basic pipe() call
- Add debug prints to track LoRA loading status
- Should resolve static output issues
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -74,24 +74,40 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
|
|
| 74 |
generator = torch.Generator().manual_seed(seed)
|
| 75 |
|
| 76 |
# Load selected LoRA
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
pipe.load_lora_weights(loaded_loras[lora_selection])
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
prompt=prompt,
|
| 86 |
guidance_scale=guidance_scale,
|
| 87 |
num_inference_steps=num_inference_steps,
|
| 88 |
width=width,
|
| 89 |
height=height,
|
| 90 |
generator=generator,
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
):
|
| 94 |
-
yield img, seed
|
| 95 |
|
| 96 |
examples = [
|
| 97 |
"a tiny astronaut hatching from an egg on the moon",
|
|
|
|
| 74 |
generator = torch.Generator().manual_seed(seed)
|
| 75 |
|
| 76 |
# Load selected LoRA
|
| 77 |
+
try:
|
| 78 |
+
# First unload any existing LoRAs
|
| 79 |
+
pipe.unload_lora_weights()
|
| 80 |
+
|
| 81 |
+
if lora_selection != "None" and lora_selection in loaded_loras:
|
| 82 |
pipe.load_lora_weights(loaded_loras[lora_selection])
|
| 83 |
+
print(f"Loaded LoRA: {lora_selection}")
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f"Failed to load LoRA {lora_selection}: {e}")
|
| 86 |
|
| 87 |
+
try:
|
| 88 |
+
for img in pipe.flux_pipe_call_that_returns_an_iterable_of_images(
|
| 89 |
+
prompt=prompt,
|
| 90 |
+
guidance_scale=guidance_scale,
|
| 91 |
+
num_inference_steps=num_inference_steps,
|
| 92 |
+
width=width,
|
| 93 |
+
height=height,
|
| 94 |
+
generator=generator,
|
| 95 |
+
output_type="pil",
|
| 96 |
+
good_vae=good_vae,
|
| 97 |
+
):
|
| 98 |
+
yield img, seed
|
| 99 |
+
except Exception as e:
|
| 100 |
+
print(f"Error during generation: {e}")
|
| 101 |
+
# Fallback to basic generation
|
| 102 |
+
img = pipe(
|
| 103 |
prompt=prompt,
|
| 104 |
guidance_scale=guidance_scale,
|
| 105 |
num_inference_steps=num_inference_steps,
|
| 106 |
width=width,
|
| 107 |
height=height,
|
| 108 |
generator=generator,
|
| 109 |
+
).images[0]
|
| 110 |
+
yield img, seed
|
|
|
|
|
|
|
| 111 |
|
| 112 |
examples = [
|
| 113 |
"a tiny astronaut hatching from an egg on the moon",
|