11# Get Access
2-
32[ labs.openai.com/waitlist] ( https://labs.openai.com/waitlist )
43
5- - Go to https://labs.openai.com/
6- - Open Network Tab in Developer Tools
7- - Type a prompt and press "Generate"
8- - Look for fetch to https://labs.openai.com/api/labs/tasks
9- - In the request header look for authorization then get the Bearer Token
10-
11-
12- # Usage
4+ # Installation
135``` bash
146pip install dalle2
157```
8+
9+ # Usage
10+ ## Setup
11+ 1 . Go to https://labs.openai.com/
12+ 1 . Open Network Tab in Developer Tools
13+ 1 . Type a prompt and press "Generate"
14+ 1 . Look for fetch to https://labs.openai.com/api/labs/tasks
15+ 1 . In the request header look for authorization then get the Bearer Token
16+
1617``` python
1718from dalle2 import Dalle2
18-
1919dalle = Dalle2(" sess-xxxxxxxxxxxxxxxxxxxxxxxxxxxx" )
20- generations = dalle.generate( " portal to another dimension, digital art " )
20+ ```
2121
22+ ## Generate images
23+ ``` python
24+ generations = dalle.generate(" portal to another dimension, digital art" )
2225print (generations)
2326```
2427
2528```
26- ✔️ Task created with ID: task-f77yxcsdf3OEm and PROMPT: portal to another dimension, digital art
29+ ✔️ Task created with ID: task-xsuhOthvBXLEjddn3ynyiiOR
2730⌛ Waiting for task to finish...
31+ ...task not completed yet
32+ ...task not completed yet
33+ ...task not completed yet
34+ ...task not completed yet
2835🙌 Task completed!
2936
3037[
@@ -40,69 +47,110 @@ print(generations)
4047 'prompt_id': 'prompt-2CtaLQsgUbJHHDoJQy9Lul3T',
4148 'is_public': false
4249 },
43- {
44- 'id': 'generation-hZWt2Nasrx8R0tJjbaROfKVy',
45- 'object': 'generation',
46- 'created': 1553332711,
47- 'generation_type': 'ImageGeneration',
48- 'generation': {
49- 'image_path': 'https://openailabsprodscus.blob.core.windows.net/private/user-hadpVzldsfs28CwvEZYMUT/generations/generation...'
50- },
51- 'task_id': 'task-nERkiKhjasdSZ50yD69qewID',
52- 'prompt_id': 'prompt-2CtaLasdUbJHHfoJQy9Lul3T',
53- 'is_public': false
54- },
55- # 2 more ...
50+ # 3 more ...
5651]
5752```
5853
59- or download all generations
60-
54+ ## Download images
6155``` python
62- from dalle2 import Dalle2
56+ file_paths = dalle.download(generations)
57+ print (file_paths)
58+ ```
6359
64- dalle = Dalle2(" sess-xxxxxxxxxxxxxxxxxxxxxxxxxxxx" )
65- generations = dalle.generate_and_download(" portal to another dimension, digital art" )
60+ ```
61+ ✔️ Downloaded: C:\...\generation-XySidj4N8EN6Ok9ed15BZ2bs.png
62+ ✔️ Downloaded: C:\...\generation-IK3UdxDz77FA5SLKpQPIITdU.png
63+ ✔️ Downloaded: C:\...\generation-uNejKBXz1z6EQxJAT9pAZbof.png
64+ ✔️ Downloaded: C:\...\generation-Ol1wEqNprf34vNohmJz0iUiE.png
65+
66+ [
67+ 'C:/.../generation-pvi9TEWrhciLyFIlfgF1XUHF.png',
68+ 'C:/.../generation-xp545V8jsqhSKKyJydHZPL50.png',
69+ 'C:/.../generation-wNODqnBhvzYvXasonBn1anIA.png',
70+ 'C:/.../generation-InPSaWWxpapT8TJD0kI71hNM.png'
71+ ]
72+ ```
6673
74+ ## Generate images and download them
75+ ``` python
76+ file_paths = dalle.generate_and_download(" portal to another dimension, digital art" )
6777```
6878
6979```
70- ✔️ Task created with ID: task-f77sayxcSGdfOEm and PROMPT: portal to another dimension, digital art
80+ ✔️ Task created with ID: task-xsuhOthvBXLEjddn3ynyiiOR
7181⌛ Waiting for task to finish...
82+ ...task not completed yet
83+ ...task not completed yet
84+ ...task not completed yet
85+ ...task not completed yet
7286🙌 Task completed!
73- Download to directory: C:\Users\pc\dalle2
74- ✔️ Downloaded: generation-fAq4Lyxcm7pQVDBQEWJ.jpg
75- ✔️ Downloaded: generation-zqfBC3yyxcPXRlW6zLP.jpg
76- ✔️ Downloaded: generation-soR3ryxcoeixzdyHG.jpg
77- ✔️ Downloaded: generation-lT5L4yxc2DOiGRwJi.jpg
87+ ✔️ Downloaded: C:\...\generation-XySidj4N8EN6Ok9ed15BZ2bs.png
88+ ✔️ Downloaded: C:\...\generation-IK3UdxDz77FA5SLKpQPIITdU.png
89+ ✔️ Downloaded: C:\...\generation-uNejKBXz1z6EQxJAT9pAZbof.png
90+ ✔️ Downloaded: C:\...\generation-Ol1wEqNprf34vNohmJz0iUiE.png
7891```
7992
80-
81- or generate a specific amount
82-
93+ ## Generate a specific number of images
8394``` python
84- from dalle2 import Dalle2
85-
86- dalle = Dalle2(" sess-xxxxxxxxxxxxxxxxxxxxxxxxxxxx" )
87- generations = dalle.generate_amount(" portal to another dimension" , 12 ) # Every generation has batch size 4 -> amount % 4 == 0 works best
88-
89- print (generations)
95+ generations = dalle.generate_amount(" portal to another dimension" , 8 ) # Every generation has batch size 4 -> amount % 4 == 0 works best
9096```
9197
9298```
93- ✔️ Task created with ID: task-lm0V4nZasgAFasd7AsStE67 and PROMPT: portal to another dimension OVERALL: 1/ 2
99+ ✔️ Task created with ID: task-lm0V4nZasgAFasd7AsStE67
100+ ⌛ Waiting for task to finish...
101+ ...task not completed yet
102+ ...task not completed yet
103+ ...task not completed yet
104+ ...task not completed yet
105+ 🙌 Task completed!
106+ ✔️ Task created with ID: task-WcetZOHt8asdvHb433gi
94107⌛ Waiting for task to finish...
95- ➕ Appended new generations to all_generations
96- ✔️ Task created with ID: task-WcetZOHt8asdvHb433gi and PROMPT: portal to another dimension OVERALL: 2/ 2
97- ⌛ Waiting for task to finish ..
98- ➕ Appended new generations to all_generations
108+ ...task not completed yet
109+ ... task not completed yet
110+ ... task not completed yet
111+ ...task not completed yet
99112🙌 Task completed!
113+ ```
114+
115+ ## Generate images from a masked file
116+ DALL·E supports an "inpainting" API that fills-in transparent parts of an image.
117+ The website provides a tool to paint over an existing image to indicate which
118+ parts you want to be transparent. This Python package call assumes that the
119+ image you provide has already been processed to have transparent parts.
100120
121+ ``` python
122+ # make the right half of a saved image transparent
123+ from PIL import Image, ImageDraw
124+
125+ image = Image.open(' my_image.png' )
126+ m, n = image.size
127+
128+ area_to_keep = (0 , 0 , m// 2 , n)
129+ image_alpha = Image.new(" L" , image.size, 0 )
130+ draw = ImageDraw.Draw(image_alpha)
131+ draw.rectangle(area_to_keep, fill = 255 )
132+
133+ image_rgba = image.copy()
134+ image_rgba.putalpha(image_alpha)
135+ image_rgba.save(' image_with_transparent_right_half.png' )
136+
137+ # ask DALL·E to fill-in the transparent right half
138+ generations = dalle.generate_from_masked_image(
139+ " portal to another dimension, digital art" ,
140+ " image_with_transparent_right_half.png" ,
141+ )
101142```
143+
102144```
103- -> [list]
145+ ✔️ Task created with ID: task-xsuhOthvBXLEjddn3ynyiiOR
146+ ⌛ Waiting for task to finish...
147+ ...task not completed yet
148+ ...task not completed yet
149+ ...task not completed yet
150+ ...task not completed yet
151+ ...task not completed yet
152+ 🙌 Task completed!
104153```
105154
155+ # Try it!
106156[ ![ Test In Colab] ( https://colab.research.google.com/assets/colab-badge.svg )] ( https://colab.research.google.com/drive/1EEgZNAI58V_OiEfRJQSsQV_xkhHzQeRB?usp=sharing )
107-
108-
0 commit comments