189 190 return best_prompt 191 192 def generate_caption(self, pil_image: Image, input_txt = "") -> str: 193 assert self.caption_model is not None, "No caption model loaded." 194 self._prepare_caption() 195 196 if input_txt:
416 return [top_labels[i] for i in tops] 417 418 419 def _download_file(url: str, filepath: str, chunk_size: int = 4*1024*1024, quiet: bool = False): 420 r = requests.get(url, stream=True) 421 if r.status_code != 200: 422 return 423
405 - rescale these crops to have ~target_n_pixels 406 - return resized images 407 """ 408 409 assert len(imgs) > 1 410 imgs = [np.array(img) for img in imgs] 411 412 # Get center crops at same aspect ratio
567 files = [os.path.join(folder, f) for f in os.listdir(folder)] 568 files = [f for f in files if os.path.isfile(f)] 569 570 random.seed(seed) 571 path = random.choice(files) 572 return (path,) 573 574
850 851 # Define the mathematical function securely 852 def safe_eval(expr, x): 853 allowed_functions = {"sin": np.sin, "cos": np.cos, "exp": np.exp} # Extend this as needed 854 return eval(expr, {"__builtins__": None}, allowed_functions) 855 856 # Create a vectorized version of the safe_eval function 857 vectorized_func = np.vectorize(lambda x: safe_eval(math_string, x))
162 pos_embed, 163 cache_dir: str, 164 non_embedded_image_filenames: str, 165 ): 166 assert pos_embed.ndim == 3, f"Expected batch to have 3 dims but got: {pos_embed.ndim} dims" 167 assert len(non_embedded_image_filenames) == pos_embed.shape[0], f"Expected the batch size of pos_embed ({pos_embed.shape[0]}) to be the same as the number of images found in non_embedded_images_folder: {len(non_embedded_image_filenames)}. non_embedded_image_filenames: {non_embedded_image_filenames}" 168 169 all_image_ids = [
163 cache_dir: str, 164 non_embedded_image_filenames: str, 165 ): 166 assert pos_embed.ndim == 3, f"Expected batch to have 3 dims but got: {pos_embed.ndim} dims" 167 assert len(non_embedded_image_filenames) == pos_embed.shape[0], f"Expected the batch size of pos_embed ({pos_embed.shape[0]}) to be the same as the number of images found in non_embedded_images_folder: {len(non_embedded_image_filenames)}. non_embedded_image_filenames: {non_embedded_image_filenames}" 168 169 all_image_ids = [ 170 get_id_from_filename(filename = f)
216 delete {id}.pth 217 218 run this scan every time the node is run 219 """ 220 assert os.path.exists(cache_dir), f"Invalid cache_dir: {cache_dir}" 221 222 filenames = get_filenames_in_a_folder(folder = cache_dir) 223 all_image_filenames = find_all_filenames_with_extension(
252 ) 253 254 for embedding_filename in embedding_filenames_to_be_deleted: 255 print(f"[FolderScanner] Deleting: {embedding_filename}") 256 os.system( 257 f"rm {embedding_filename}" 258 ) 259 260 return (image_filenames_without_embeddings,) 261
359 360 style_directions = [] 361 362 # Ensure that num_style_components is not greater than the size of the first dimension 363 assert num_style_components <= style_embeddings.size(0), "num_style_components is greater than the number of style images!" 364 365 for i in range(num_samples): 366 # Sample the style images to use: