akazmi commited on
Commit
a23c39b
·
verified ·
1 Parent(s): a47c1ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,17 +1,20 @@
1
- from transformers import pipeline
2
 
3
- # Define your API key
4
  api_key = "your_huggingface_api_key"
5
 
6
- # Initialize the pipeline using the API key
7
- generator = pipeline(
8
- "image-generation",
9
- model="CompVis/stable-diffusion-v1-4-original",
10
  use_auth_token=api_key
11
  )
12
 
13
- # Generate an image
14
- result = generator("A futuristic city")
 
15
 
16
- # Display the generated image
17
- result[0]["image"].show()
 
 
 
 
1
+ from diffusers import StableDiffusionPipeline
2
 
3
+ # Replace with your Hugging Face API key
4
  api_key = "your_huggingface_api_key"
5
 
6
+ # Load the Stable Diffusion pipeline
7
+ pipeline = StableDiffusionPipeline.from_pretrained(
8
+ "stabilityai/stable-diffusion-v1-5-base",
 
9
  use_auth_token=api_key
10
  )
11
 
12
+ # Generate an image from a text prompt
13
+ prompt = "A serene mountain landscape at sunset with a lake reflecting the sky"
14
+ image = pipeline(prompt).images[0]
15
 
16
+ # Save the generated image to a file
17
+ image.save("generated_image_v1_5.png")
18
+
19
+ # Optionally display the image if your environment supports it
20
+ image.show()