Skip to content

Commit e924707

Browse files
add download
1 parent e9b8ca3 commit e924707

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ from dalle2 import Dalle2
1919
dalle = Dalle2("sess-xxxxxxxxxxxxxxxxxxxxxxxxxxxx")
2020
generations = dalle.generate("portal to another dimension, digital art")
2121

22+
2223
print(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+
```

src/dalle2/dalle2.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import requests
22
import json
33
import time
4+
import urllib
5+
import urllib.request
6+
import os
47

58
class 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

0 commit comments

Comments
 (0)