Guest User

Untitled

a guest
Jun 14th, 2024
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. import sys
  2. import os
  3. sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
  4.  
  5. import nodes
  6. import folder_paths
  7.  
  8.  
  9. class LoadOffset:
  10.     @classmethod
  11.     def INPUT_TYPES(s):
  12.         input_dir = folder_paths.get_input_directory()
  13.         files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))]
  14.         return {
  15.             "required": {
  16.                 "image": (sorted(files), {"image_upload": True}),
  17.                 "vae": ("VAE",),
  18.                 "width":("INT", {
  19.                     "default": 512,
  20.                     "min": 256,
  21.                     "max": 2048,
  22.                     "step": 64
  23.                 }),
  24.                 "height": ("INT", {
  25.                     "default": 512,
  26.                     "min": 256,
  27.                     "max": 2048,
  28.                     "step": 64
  29.                 }),
  30.                 "repeat": ("INT", {
  31.                     "default": 1,
  32.                     "min": 1,
  33.                     "max": 128,
  34.                     "step": 1
  35.                 })
  36.             },
  37.         }
  38.  
  39.     CATEGORY = "latent"
  40.  
  41.     RETURN_TYPES = ("LATENT",)
  42.     FUNCTION = "load_image"
  43.     def load_image(self, image, vae, width, height, repeat):
  44.         loader = nodes.LoadImage()
  45.         scaler = nodes.ImageScale()
  46.         encoder = nodes.VAEEncode()
  47.         repeater = nodes.RepeatLatentBatch()
  48.  
  49.         img,_ = loader.load_image(image)
  50.         img, = scaler.upscale(img, "bicubic", width, height, False)
  51.         latent, = encoder.encode(vae, img)
  52.         latents, = repeater.repeat(latent, repeat)
  53.  
  54.         return latents,
  55.  
  56. NODE_CLASS_MAPPINGS = {
  57.     "LoadOffset": LoadOffset,
  58. }
  59.  
  60. # A dictionary that contains the friendly/humanly readable titles for the nodes
  61. NODE_DISPLAY_NAME_MAPPINGS = {
  62.     "LoadOffset": "Load image as latent",
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment