Update app.py
Browse files
app.py
CHANGED
@@ -16,22 +16,21 @@ model_id = "stabilityai/stable-diffusion-3.5-medium"
|
|
16 |
pipe = StableDiffusion3Pipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
17 |
pipe.to("cpu")
|
18 |
|
19 |
-
# Define the path to the LoRA model
|
20 |
-
lora_model_path = "https://huggingface.co/spaces/DonImages/Testing2/resolve/main/lora_model.pth" # LoRA model path
|
21 |
-
|
22 |
# Custom method to load and apply LoRA weights to the Stable Diffusion pipeline
|
23 |
def load_lora_model(pipe, lora_model_path):
|
24 |
# Load the LoRA weights (assuming it's a PyTorch .pth file)
|
25 |
lora_weights = torch.load(lora_model_path, map_location="cpu")
|
26 |
|
27 |
-
#
|
28 |
-
# Here, we just load the weights into the model's parameters (this is a conceptual approach)
|
29 |
for name, param in pipe.named_parameters():
|
30 |
if name in lora_weights:
|
31 |
param.data += lora_weights[name] # Apply LoRA weights to the parameters
|
32 |
|
33 |
return pipe # Return the updated model
|
34 |
|
|
|
|
|
|
|
35 |
# Load and apply the LoRA model weights
|
36 |
pipe = load_lora_model(pipe, lora_model_path)
|
37 |
|
|
|
16 |
pipe = StableDiffusion3Pipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
17 |
pipe.to("cpu")
|
18 |
|
|
|
|
|
|
|
19 |
# Custom method to load and apply LoRA weights to the Stable Diffusion pipeline
|
20 |
def load_lora_model(pipe, lora_model_path):
|
21 |
# Load the LoRA weights (assuming it's a PyTorch .pth file)
|
22 |
lora_weights = torch.load(lora_model_path, map_location="cpu")
|
23 |
|
24 |
+
# Apply LoRA weights to the parameters of the model
|
|
|
25 |
for name, param in pipe.named_parameters():
|
26 |
if name in lora_weights:
|
27 |
param.data += lora_weights[name] # Apply LoRA weights to the parameters
|
28 |
|
29 |
return pipe # Return the updated model
|
30 |
|
31 |
+
# Define the path to the LoRA model (Local path in your Hugging Face Space)
|
32 |
+
lora_model_path = "./lora_model.pth" # Local path to LoRA model
|
33 |
+
|
34 |
# Load and apply the LoRA model weights
|
35 |
pipe = load_lora_model(pipe, lora_model_path)
|
36 |
|