@@ -229,6 +229,49 @@ def list(cls, args):
229229 print (file )
230230
231231
232+ class DALLE :
233+ @classmethod
234+ def generations (cls , args ):
235+ resp = openai .DALLE .generations (
236+ prompt = args .prompt ,
237+ model = args .model ,
238+ size = args .size ,
239+ num_images = args .num_images ,
240+ response_format = args .response_format ,
241+ )
242+ print (resp )
243+
244+ @classmethod
245+ def variations (cls , args ):
246+ with open (args .image , "rb" ) as file_reader :
247+ buffer_reader = BufferReader (file_reader .read (), desc = "Upload progress" )
248+ resp = openai .DALLE .variations (
249+ image = buffer_reader ,
250+ model = args .model ,
251+ size = args .size ,
252+ num_images = args .num_images ,
253+ response_format = args .response_format ,
254+ )
255+ print (resp )
256+
257+ @classmethod
258+ def edits (cls , args ):
259+ with open (args .image , "rb" ) as file_reader :
260+ image_reader = BufferReader (file_reader .read (), desc = "Upload progress" )
261+ with open (args .mask , "rb" ) as file_reader :
262+ mask_reader = BufferReader (file_reader .read (), desc = "Upload progress" )
263+ resp = openai .DALLE .edits (
264+ image = image_reader ,
265+ mask = mask_reader ,
266+ prompt = args .prompt ,
267+ model = args .model ,
268+ size = args .size ,
269+ num_images = args .num_images ,
270+ response_format = args .response_format ,
271+ )
272+ print (resp )
273+
274+
232275class Search :
233276 @classmethod
234277 def prepare_data (cls , args , purpose ):
@@ -983,6 +1026,57 @@ def help(args):
9831026 sub .add_argument ("-i" , "--id" , required = True , help = "The id of the fine-tune job" )
9841027 sub .set_defaults (func = FineTune .cancel )
9851028
1029+ # DALLE
1030+ sub = subparsers .add_parser ("dalle.generations" )
1031+ sub .add_argument ("-m" , "--model" , type = str , default = "image-alpha-001" )
1032+ sub .add_argument ("-p" , "--prompt" , type = str , required = True )
1033+ sub .add_argument ("-n" , "--num-images" , type = int , default = 1 )
1034+ sub .add_argument (
1035+ "-s" , "--size" , type = str , default = "1024x1024" , help = "Size of the output image"
1036+ )
1037+ sub .add_argument ("--response-format" , type = str , default = "url" )
1038+ sub .set_defaults (func = DALLE .generations )
1039+
1040+ sub = subparsers .add_parser ("dalle.edits" )
1041+ sub .add_argument ("-m" , "--model" , type = str , default = "image-alpha-001" )
1042+ sub .add_argument ("-p" , "--prompt" , type = str , required = True )
1043+ sub .add_argument ("-n" , "--num-images" , type = int , default = 1 )
1044+ sub .add_argument (
1045+ "-I" ,
1046+ "--image" ,
1047+ type = str ,
1048+ required = True ,
1049+ help = "Image to modify. Should be a local path and a PNG encoded image." ,
1050+ )
1051+ sub .add_argument (
1052+ "-s" , "--size" , type = str , default = "1024x1024" , help = "Size of the output image"
1053+ )
1054+ sub .add_argument ("--response-format" , type = str , default = "url" )
1055+ sub .add_argument (
1056+ "-M" ,
1057+ "--mask" ,
1058+ type = str ,
1059+ required = True ,
1060+ help = "Path to a mask image. It should be the same size as the image you're editing and a RGBA PNG image. The Alpha channel acts as the mask." ,
1061+ )
1062+ sub .set_defaults (func = DALLE .edits )
1063+
1064+ sub = subparsers .add_parser ("dalle.variations" )
1065+ sub .add_argument ("-m" , "--model" , type = str , default = "image-alpha-001" )
1066+ sub .add_argument ("-n" , "--num-images" , type = int , default = 1 )
1067+ sub .add_argument (
1068+ "-I" ,
1069+ "--image" ,
1070+ type = str ,
1071+ required = True ,
1072+ help = "Image to modify. Should be a local path and a PNG encoded image." ,
1073+ )
1074+ sub .add_argument (
1075+ "-s" , "--size" , type = str , default = "1024x1024" , help = "Size of the output image"
1076+ )
1077+ sub .add_argument ("--response-format" , type = str , default = "url" )
1078+ sub .set_defaults (func = DALLE .variations )
1079+
9861080
9871081def wandb_register (parser ):
9881082 subparsers = parser .add_subparsers (
0 commit comments