Create run.py
Browse files
run.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
|
| 4 |
+
# Load the Stable Diffusion pipeline
|
| 5 |
+
pipeline = StableDiffusionPipeline.from_pretrained(
|
| 6 |
+
"runwayml/stable-diffusion-v1-5",
|
| 7 |
+
torch_dtype=torch.float16
|
| 8 |
+
)
|
| 9 |
+
pipeline.to("cuda") # Use the GPU
|
| 10 |
+
|
| 11 |
+
# Load your safetensors weights
|
| 12 |
+
pipeline.unet.load_attn_procs("v1-5-pruned-emaonly.safetensors")
|
| 13 |
+
|
| 14 |
+
# Generate an image
|
| 15 |
+
prompt = "A serene landscape with mountains and a lake at sunset"
|
| 16 |
+
result = pipeline(prompt, guidance_scale=7.5) # Adjust guidance scale if needed
|
| 17 |
+
image = result.images[0]
|
| 18 |
+
|
| 19 |
+
# Save and display the image
|
| 20 |
+
image.save("generated_image.png")
|
| 21 |
+
image.show()
|