SandaAbhishekSagar
commited on
Commit
·
426c440
1
Parent(s):
527e09e
fixed image-generation code
Browse files- image_generator.py +20 -1
image_generator.py
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from diffusers import StableDiffusionPipeline
|
|
|
|
| 2 |
|
| 3 |
def generate_image(prompt):
|
| 4 |
model = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
image = model(prompt).images[0]
|
| 7 |
image.save("output.png")
|
| 8 |
return "output.png"
|
|
|
|
| 1 |
+
# from diffusers import StableDiffusionPipeline
|
| 2 |
+
|
| 3 |
+
# def generate_image(prompt):
|
| 4 |
+
# model = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
|
| 5 |
+
# model.to("cuda") # Use GPU for faster generation
|
| 6 |
+
# image = model(prompt).images[0]
|
| 7 |
+
# image.save("output.png")
|
| 8 |
+
# return "output.png"
|
| 9 |
+
|
| 10 |
+
# if __name__ == "__main__":
|
| 11 |
+
# prompt = "A friendly person saying 'How are you?'"
|
| 12 |
+
# print("Generated Image Path:", generate_image(prompt))
|
| 13 |
+
|
| 14 |
+
|
| 15 |
from diffusers import StableDiffusionPipeline
|
| 16 |
+
import torch
|
| 17 |
|
| 18 |
def generate_image(prompt):
|
| 19 |
model = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
|
| 20 |
+
|
| 21 |
+
# Use GPU if available, otherwise fallback to CPU
|
| 22 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 23 |
+
model.to(device)
|
| 24 |
+
|
| 25 |
image = model(prompt).images[0]
|
| 26 |
image.save("output.png")
|
| 27 |
return "output.png"
|