Update appCODE.py
Browse files- appCODE.py +9 -4
appCODE.py
CHANGED
@@ -6,7 +6,6 @@ import random
|
|
6 |
from diffusers import StableDiffusion3Pipeline
|
7 |
from diffusers.loaders import SD3LoraLoaderMixin
|
8 |
|
9 |
-
|
10 |
# Device selection
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
@@ -28,9 +27,15 @@ pipeline = StableDiffusion3Pipeline.from_pretrained(
|
|
28 |
lora_path = "lora_trained_model.pt" # Ensure this file is uploaded in the Space
|
29 |
if os.path.exists(lora_path):
|
30 |
try:
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
print(f"❌ Error loading LoRA: {e}")
|
35 |
else:
|
36 |
print("⚠️ LoRA file not found! Running base model.")
|
|
|
6 |
from diffusers import StableDiffusion3Pipeline
|
7 |
from diffusers.loaders import SD3LoraLoaderMixin
|
8 |
|
|
|
9 |
# Device selection
|
10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
|
|
27 |
lora_path = "lora_trained_model.pt" # Ensure this file is uploaded in the Space
|
28 |
if os.path.exists(lora_path):
|
29 |
try:
|
30 |
+
# Check if LoRA is supported by your pipeline's version
|
31 |
+
if hasattr(pipeline, 'load_lora_weights'):
|
32 |
+
pipeline.load_lora_weights(lora_path) # This automatically applies to the right components
|
33 |
+
print("✅ LoRA weights loaded successfully!")
|
34 |
+
else:
|
35 |
+
print("❌ LoRA weights method not available. Manually loading weights.")
|
36 |
+
# Optionally, you can manually load the weights using keys (refer to your printed keys)
|
37 |
+
# Example: pipeline.model.load_state_dict(torch.load(lora_path))
|
38 |
+
except Exception as e:
|
39 |
print(f"❌ Error loading LoRA: {e}")
|
40 |
else:
|
41 |
print("⚠️ LoRA file not found! Running base model.")
|