File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -19,10 +19,15 @@ from dalle2 import Dalle2
1919dalle = Dalle2(" sess-xxxxxxxxxxxxxxxxxxxxxxxxxxxx" )
2020generations = dalle.generate(" portal to another dimension, digital art" )
2121
22+
2223print (generations)
2324```
2425
2526```
27+ ✔️ Task created with ID: task-f77yxcsdf3OEm and PROMT: portal to another dimension, digital art
28+ ⌛ Waiting for task to finish ..
29+ 🙌 Task completed!
30+
2631[
2732 {
2833 'id': 'generation-sCnERSYDPP0Zu14fsdXEcKmL',
@@ -52,3 +57,26 @@ print(generations)
5257]
5358```
5459
60+ or download all generations
61+
62+ ``` python
63+ from dalle2 import Dalle2
64+
65+ dalle = Dalle2(" sess-xxxxxxxxxxxxxxxxxxxxxxxxxxxx" )
66+ generations = dalle.generate_and_download(" portal to another dimension, digital art" )
67+
68+ ```
69+
70+ ```
71+ ✔️ Task created with ID: task-f77sayxcSGdfOEm and PROMT: portal to another dimension, digital art
72+ ⌛ Waiting for task to finish ..
73+ 🙌 Task completed!
74+ Download to directory: C:\Users\pc\dalle2
75+ ✔️ Downloaded: generation-fAq4Lyxcm7pQVDBQEWJ.jpg
76+ ✔️ Downloaded: generation-zqfBC3yyxcPXRlW6zLP.jpg
77+ ✔️ Downloaded: generation-soR3ryxcoeixzdyHG.jpg
78+ ✔️ Downloaded: generation-lT5L4yxc2DOiGRwJi.jpg
79+ ✔️ Downloaded: generation-01DvPryxcq2BX1NOREL.jpg
80+ ✔️ Downloaded: generation-AAs4yxcczH1vl19FidR.jpg
81+
82+ ```
Original file line number Diff line number Diff line change 11import requests
22import json
33import time
4+ import urllib
5+ import urllib .request
6+ import os
47
58class Dalle2 ():
69 def __init__ (self , bearer ):
@@ -40,4 +43,20 @@ def generate(self, promt):
4043 # print("Task not completed yet")
4144 time .sleep (3 )
4245 continue
46+
47+ def generate_and_download (self , promt ):
48+ generations = self .generate (promt )
49+ if generations is None :
50+ return None
51+
52+ print ("Download to directory: " + os .getcwd ())
53+ #print(generations)
54+ for generation in generations :
55+ imageurl = generation ["generation" ]["image_path" ]
56+ id = generation ["id" ]
57+
58+ urllib .request .urlretrieve (imageurl , id + ".jpg" )
59+ print ("✔️ Downloaded: " , id + ".jpg" )
60+
61+
4362
You can’t perform that action at this time.
0 commit comments