Create Generate.py
Browse files- Generate.py +25 -0
Generate.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import StableDiffusionPipeline
|
2 |
+
import torch
|
3 |
+
import PIL
|
4 |
+
from IPython.display import display
|
5 |
+
|
6 |
+
# Load the base model
|
7 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
8 |
+
"runwayml/stable-diffusion-v1-5", # base model
|
9 |
+
torch_dtype=torch.float16,
|
10 |
+
).to("cuda")
|
11 |
+
|
12 |
+
# Load your LoRA
|
13 |
+
pipe.load_lora_weights("Flo444/example-lora-realistic")
|
14 |
+
|
15 |
+
# Fuse LoRA (optional: set strength 0.7 or whatever you want)
|
16 |
+
pipe.fuse_lora(lora_scale=0.7)
|
17 |
+
|
18 |
+
# Prompt
|
19 |
+
prompt = "beautiful realistic landscape, mountains, river"
|
20 |
+
|
21 |
+
# Generate
|
22 |
+
image = pipe(prompt, num_inference_steps=30, guidance_scale=7).images[0]
|
23 |
+
|
24 |
+
# Display the image directly in Colab
|
25 |
+
display(image)
|