def generate(
        self,
        pos_prompts,
        neg_prompts=None,
        image_path=None,
        show_intermediate=True,
        save_intermediate=False,
        show_final=True,
        save_final=True,
        save_path=None,
    ):
        """Generate an image from the given prompts.
        If image_path is provided, the image is used as a starting point for the optimization.
        If image_path is not provided, a random latent vector is used as a starting point.
        You must provide at least one positive prompt, and optionally provide negative prompts.
        Prompts must be formatted in one of the following ways:
        - A single prompt as a string, e.g "A smiling woman"
        - A set of prompts separated by pipes: "A smiling woman | a woman with brown hair"
        - A set of prompts and their weights separated by colons: "A smiling woman:1 | a woman with brown hair: 3" (default weight is 1)
        - A list of prompts, e.g ["A smiling woman", "a woman with brown hair"]
        - A list of prompts and weights, e.g [("A smiling woman", 1), ("a woman with brown hair", 3)]
        """
        if image_path:
            self.latent = self._get_latent(image_path)
        else:
            self.latent = torch.randn(self.latent_dim, device=self.device)
        if self.log:
            self._init_logging(pos_prompts, neg_prompts, image_path)

        assert pos_prompts, "You must provide at least one positive prompt."
        pos_prompts = self.process_prompts(pos_prompts)
        neg_prompts = self.process_prompts(neg_prompts)
        if save_final and save_path is None:
            save_path = os.path.join("./outputs/", "_".join(pos_prompts["prompts"]))
        if not os.path.exists(save_path):
            os.makedirs(save_path)
        else:
            save_path = save_path + "_" + get_timestamp()
            os.makedirs(save_path)
        self.save_path = save_path

        original_img = self.vqgan.decode(self.latent)[0]
        if show_intermediate:
            print("Original Image")
            show_pil(custom_to_pil(original_img))

        original_img = loop_post_process(original_img)
        for iter, transformed_img in enumerate(self._optimize_CLIP(original_img, pos_prompts, neg_prompts)):
            if show_intermediate:
                show_pil(transformed_img)
            if save_intermediate:
                transformed_img.save(os.path.join(self.save_path, f"iter_{iter:03d}.png"))
            if self.log:
                wandb.log({"Image": wandb.Image(transformed_img)})
        if show_final:
            show_pil(transformed_img)
        if save_final:
            transformed_img.save(os.path.join(self.save_path, f"iter_{iter:03d}_final.png"))
Generate an image from the given prompts.
        If image_path is provided, the image is used as a starting point for the optimization.
        If image_path is not provided, a random latent vector is used as a starting point.
        You must provide at least one positive prompt, and optionally provide negative prompts.
        Prompts must be formatted in one of the following ways:
        - A single prompt as a string, e.g "A smiling woman"
        - A set of prompts separated by pipes: "A smiling woman | a woman with brown hair"
        - A set of prompts and their weights separated by colons: "A smiling woman:1 | a woman with brown hair: 3" (default weight is 1)
        - A list of prompts, e.g ["A smiling woman", "a woman with brown hair"]
        - A list of prompts and weights, e.g [("A smiling woman", 1), ("a woman with brown hair", 3)]
        
dpkd/transformers/examples/research_projects/vqgan-clip/VQGAN_CLIP.py