File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api"
12
12
13
13
[tool .poetry ]
14
14
name = " together"
15
- version = " 1.3.0 "
15
+ version = " 1.3.1 "
16
16
authors = [
17
17
18
18
]
Original file line number Diff line number Diff line change 1
1
import base64
2
2
import pathlib
3
+ import requests
3
4
4
5
import click
5
6
from PIL import Image
@@ -70,8 +71,18 @@ def generate(
70
71
for i , choice in enumerate (response .data ):
71
72
assert isinstance (choice , ImageChoicesData )
72
73
74
+ data = None
75
+ if choice .b64_json :
76
+ data = base64 .b64decode (choice .b64_json )
77
+ elif choice .url :
78
+ data = requests .get (choice .url ).content
79
+
80
+ if not data :
81
+ click .echo (f"Image [{ i + 1 } /{ len (response .data )} ] is empty" )
82
+ continue
83
+
73
84
with open (f"{ output } /{ prefix } { choice .index } .png" , "wb" ) as f :
74
- f .write (base64 . b64decode ( choice . b64_json ) )
85
+ f .write (data )
75
86
76
87
click .echo (
77
88
f"Image [{ i + 1 } /{ len (response .data )} ] saved to { output } /{ prefix } { choice .index } .png"
Original file line number Diff line number Diff line change @@ -28,7 +28,9 @@ class ImageChoicesData(BaseModel):
28
28
# response index
29
29
index : int
30
30
# base64 image response
31
- b64_json : str
31
+ b64_json : str | None = None
32
+ # URL hosting image
33
+ url : str | None = None
32
34
33
35
34
36
class ImageResponse (BaseModel ):
You can’t perform that action at this time.
0 commit comments