Spaces:
Runtime error
Runtime error
kasper-boy
commited on
Create Working_TTI_CPU.py
Browse files- Working_TTI_CPU.py +23 -0
Working_TTI_CPU.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import DiffusionPipeline
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Load the model
|
6 |
+
pipe = DiffusionPipeline.from_pretrained(
|
7 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
8 |
+
torch_dtype=torch.float32, # Use float32 for CPU
|
9 |
+
use_safetensors=True
|
10 |
+
)
|
11 |
+
pipe.to("cpu")
|
12 |
+
|
13 |
+
# Define the prompt
|
14 |
+
prompt = "An astronaut riding a green horse"
|
15 |
+
|
16 |
+
# Generate the image
|
17 |
+
result = pipe(prompt=prompt)
|
18 |
+
image = result.images[0]
|
19 |
+
|
20 |
+
# Save the image
|
21 |
+
image.save("generated_image.png")
|
22 |
+
|
23 |
+
print("Image saved as generated_image.png")
|