Update app.py
Browse files
app.py
CHANGED
|
@@ -25,19 +25,17 @@ pipeline = StableDiffusion3Pipeline.from_pretrained(
|
|
| 25 |
# Load the LoRA trained weights once at the start
|
| 26 |
lora_path = "lora_trained_model.pt" # Ensure this file is uploaded in the Space
|
| 27 |
if os.path.exists(lora_path):
|
| 28 |
-
|
| 29 |
|
| 30 |
try:
|
| 31 |
-
# Assuming
|
| 32 |
-
|
| 33 |
-
|
| 34 |
print("✅ LoRA weights loaded successfully!")
|
| 35 |
-
except
|
| 36 |
-
print("❌
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
# Example:
|
| 40 |
-
# pipeline.model.load_state_dict(lora_state_dict, strict=False)
|
| 41 |
else:
|
| 42 |
print("⚠️ LoRA file not found! Running base model.")
|
| 43 |
|
|
|
|
| 25 |
# Load the LoRA trained weights once at the start
|
| 26 |
lora_path = "lora_trained_model.pt" # Ensure this file is uploaded in the Space
|
| 27 |
if os.path.exists(lora_path):
|
| 28 |
+
lora_checkpoint = torch.load(lora_path, map_location=device)
|
| 29 |
|
| 30 |
try:
|
| 31 |
+
# Assuming the checkpoint contains 'model' key with the model state dict
|
| 32 |
+
pipeline.unet.load_state_dict(lora_checkpoint['model'], strict=False) # Apply weights to the unet
|
| 33 |
+
|
| 34 |
print("✅ LoRA weights loaded successfully!")
|
| 35 |
+
except KeyError as e:
|
| 36 |
+
print(f"❌ Error: Missing key in checkpoint: {e}")
|
| 37 |
+
except Exception as e:
|
| 38 |
+
print(f"❌ Error loading LoRA: {e}")
|
|
|
|
|
|
|
| 39 |
else:
|
| 40 |
print("⚠️ LoRA file not found! Running base model.")
|
| 41 |
|