Commit
·
97530d5
1
Parent(s):
8108852
Create Dalle.py
Browse files
Dalle.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import necessary libraries
|
2 |
+
from transformers import DALL_E
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
+
|
6 |
+
# Load the pre-trained DALL-E model
|
7 |
+
model = DALL_E.from_pretrained("openai/your-dall-e-model-name-here")
|
8 |
+
|
9 |
+
# Define a text description for the image you want to generate
|
10 |
+
text_description = "A cat sitting on a grassy hill under a blue sky"
|
11 |
+
|
12 |
+
# Generate an image from the text description
|
13 |
+
output = model.generate_images(text_description)
|
14 |
+
|
15 |
+
# Get the image data
|
16 |
+
image_data = requests.get(output[0]["image"]).content
|
17 |
+
|
18 |
+
# Save the image to a file or display it
|
19 |
+
with open("generated_image.jpg", "wb") as img_file:
|
20 |
+
img_file.write(image_data)
|
21 |
+
|
22 |
+
# Display the image using PIL (optional)
|
23 |
+
image = Image.open("generated_image.jpg")
|
24 |
+
image.show()
|