@@ -137,28 +137,41 @@ def create_latent(self, model_type, resolution, orientation, latent_type, image,
137137 print (f'\n \n \n FlowState Latent Chooser - { model_type } ' )
138138
139139 selected_model = model_type if isinstance (model_type , str ) else model_type [0 ]
140+ loaded_latent , loaded_img = self .load_and_encode (image , vae )
141+
142+ using_custom = resolution == 'custom'
143+ horizontal_img = orientation == 'horizontal'
144+ using_empty = latent_type == 'empty_latent'
145+ using_input = latent_type == 'input_img'
146+ have_pixels = pixels != None
147+
148+ width_to_use = loaded_img .shape [2 ]
149+ height_to_use = loaded_img .shape [1 ]
150+ res = None
151+ res_split = None
152+
153+ if using_custom and using_empty :
154+ width_to_use = custom_width
155+ height_to_use = custom_height
156+
157+ if not using_custom and using_empty :
158+ res_split = res .split (' - ' )[0 ].split ('x' )
159+ width_to_use = int (res_split [0 ]) if horizontal_img else int (res_split [1 ])
160+ height_to_use = int (res_split [1 ]) if horizontal_img else int (res_split [0 ])
161+
162+ if using_input and have_pixels :
163+ width_to_use = pixels .shape [2 ]
164+ height_to_use = pixels .shape [1 ]
140165
141166 if latent_type == 'empty_latent' :
142167 print (f' - Preparing empty latent.\n ' )
143- using_custom = resolution == 'custom'
144- horizontal_img = orientation == 'horizontal'
145- aspect_split = resolution .split (' - ' )[0 ].split ('x' )
146- aspect_w = int (aspect_split [0 ])
147- aspect_h = int (aspect_split [1 ])
148- width_to_use = custom_width if using_custom else (aspect_w if horizontal_img else aspect_h )
149- height_to_use = custom_height if using_custom else (aspect_h if horizontal_img else aspect_w )
150- latent = self .generate (width_to_use , height_to_use , selected_model )
151- return ({'samples' :latent }, vae , image , width_to_use , height_to_use , )
168+ generated_latent = self .generate (width_to_use , height_to_use , selected_model )
169+ return ({'samples' : generated_latent }, vae , loaded_img , width_to_use , height_to_use , )
152170 elif latent_type == 'input_img' :
153171 print (f' - Preparing latent from input image.' )
154- latent = vae .encode (pixels [:,:,:,:3 ])
155- img_width = pixels .shape [2 ]
156- img_height = pixels .shape [1 ]
157- return ({'samples' :latent }, vae , pixels , img_width , img_height , )
172+ input_latent = vae .encode (pixels [:,:,:,:3 ])
173+ return ({'samples' : input_latent }, vae , pixels , width_to_use , height_to_use , )
158174 else :
159175 print (f' - Preparing latent from imported image.' )
160- latent , loaded_img = self .load_and_encode (image , vae )
161- img_width = loaded_img .shape [2 ]
162- img_height = loaded_img .shape [1 ]
163- return ({'samples' :latent }, vae , loaded_img , img_width , img_height , )
176+ return ({'samples' : loaded_latent }, vae , loaded_img , width_to_use , height_to_use , )
164177
0 commit comments