panchadip commited on
Commit
2c57eba
·
verified ·
1 Parent(s): dc245b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import StableDiffusionPipeline # Import the StableDiffusionPipeline class from diffusers
2
+ import torch
3
+
4
+ # Define the model ID for Stable Diffusion
5
+ model_id = "CompVis/stable-diffusion-v1-4"
6
+
7
+ # Load the pre-trained model
8
+ pipe = StableDiffusionPipeline.from_pretrained(model_id)
9
+
10
+ # Move the model to GPU if available, otherwise use CPU
11
+ pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
12
+
13
+ # Function to generate images based on text prompts
14
+ def generate_image(prompt, output_path="generated_image.png"):
15
+ # Generate the image
16
+ image = pipe(prompt).images[0]
17
+
18
+ # Save the generated image
19
+ image.save(output_path)
20
+ print(f"Image saved at: {output_path}")
21
+
22
+ # Example prompts for image generation
23
+ prompt1 = "A futuristic city skyline at sunset"
24
+ generate_image(prompt1, "image1.png")
25
+
26
+ prompt2 = "A beautiful landscape from mountains during sunrise"
27
+ generate_image(prompt2, "image2.png")
28
+
29
+ prompt3 = "A beautiful landscape from mountains during sunset"
30
+ generate_image(prompt3, "image3.png")