File size: 731 Bytes
97530d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Import necessary libraries
from transformers import DALL_E
from PIL import Image
import requests

# Load the pre-trained DALL-E model
model = DALL_E.from_pretrained("openai/your-dall-e-model-name-here")

# Define a text description for the image you want to generate
text_description = "A cat sitting on a grassy hill under a blue sky"

# Generate an image from the text description
output = model.generate_images(text_description)

# Get the image data
image_data = requests.get(output[0]["image"]).content

# Save the image to a file or display it
with open("generated_image.jpg", "wb") as img_file:
    img_file.write(image_data)

# Display the image using PIL (optional)
image = Image.open("generated_image.jpg")
image.show()