Update app.py
Browse files
app.py
CHANGED
@@ -22,10 +22,7 @@ else:
|
|
22 |
# Load the Stable Diffusion 3.5 model with lower precision (float16)
|
23 |
model_id = "stabilityai/stable-diffusion-3.5-large"
|
24 |
pipe = StableDiffusion3Pipeline.from_pretrained(model_id, torch_dtype=torch.float16) # Use float16 precision
|
25 |
-
|
26 |
-
# Check for GPU availability and set device accordingly
|
27 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
28 |
-
pipe.to(device) # Use GPU if available, otherwise fallback to CPU
|
29 |
|
30 |
# Define the path to the LoRA model
|
31 |
lora_model_path = "./lora_model.pth" # Assuming the file is saved locally
|
@@ -33,7 +30,7 @@ lora_model_path = "./lora_model.pth" # Assuming the file is saved locally
|
|
33 |
# Custom method to load and apply LoRA weights to the Stable Diffusion pipeline
|
34 |
def load_lora_model(pipe, lora_model_path):
|
35 |
# Load the LoRA weights
|
36 |
-
lora_weights = torch.load(lora_model_path, map_location=device) #
|
37 |
|
38 |
# Apply weights to the UNet submodule
|
39 |
for name, param in pipe.unet.named_parameters(): # Accessing unet parameters
|
|
|
22 |
# Load the Stable Diffusion 3.5 model with lower precision (float16)
|
23 |
model_id = "stabilityai/stable-diffusion-3.5-large"
|
24 |
pipe = StableDiffusion3Pipeline.from_pretrained(model_id, torch_dtype=torch.float16) # Use float16 precision
|
25 |
+
pipe.to(device) # Ensuring the model is on the correct device (GPU or CPU)
|
|
|
|
|
|
|
26 |
|
27 |
# Define the path to the LoRA model
|
28 |
lora_model_path = "./lora_model.pth" # Assuming the file is saved locally
|
|
|
30 |
# Custom method to load and apply LoRA weights to the Stable Diffusion pipeline
|
31 |
def load_lora_model(pipe, lora_model_path):
|
32 |
# Load the LoRA weights
|
33 |
+
lora_weights = torch.load(lora_model_path, map_location=device) # Load LoRA model to the correct device
|
34 |
|
35 |
# Apply weights to the UNet submodule
|
36 |
for name, param in pipe.unet.named_parameters(): # Accessing unet parameters
|