CoolFace
Datasetpublic

ItchyFingaz/data

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes127downloads
1 # By WASasquatch (Discord: WAS#0263)2 3import torch, os, json, random, hashlib4from urllib.request import urlopen5import json6 7class WAS_NSP_CLIPTextEncoder:8    def __init__(self):9        pass10 11    @classmethod12    def INPUT_TYPES(s):13        return {14                    "required": {15                            "noodle_key": ("STRING", {"default": '__', "multiline": False}),16                            "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),17                            "text": ("STRING", {"multiline": True}),18                            "clip": ("CLIP",),19                    }20                }21        22    RETURN_TYPES = ("CONDITIONING",)23    FUNCTION = "nsp_encode"24 25    CATEGORY = "conditioning"26 27    def nsp_encode(self, clip, text, noodle_key = '__', seed = 0):28    29        # Fetch the NSP Pantry30        local_pantry = 'ComfyUI/custom_nodes/nsp_pantry.json'31        if not os.path.exists(local_pantry):32            response = urlopen('https://raw.githubusercontent.com/WASasquatch/noodle-soup-prompts/main/nsp_pantry.json')33            tmp_pantry = json.loads(response.read())34            # Dump JSON locally35            pantry_serialized = json.dumps(tmp_pantry, indent=4)36            with open(local_pantry, "w") as f:37                f.write(pantry_serialized)38            del response, tmp_pantry39        40        # Load local pantry41        with open(local_pantry, 'r') as f:42            nspterminology = json.load(f)43            44        if seed > 0 or seed < 1:45            random.seed(seed)46            47        # Parse Text48        new_text = text49        for term in nspterminology:50            # Target Noodle51            tkey = f'{noodle_key}{term}{noodle_key}'52            # How many occurances?53            tcount = new_text.count(tkey)54            # Apply random results for each noodle counted55            for _ in range(tcount):56                new_text = new_text.replace(tkey, random.choice(nspterminology[term]), 1)57                seed = seed+158                random.seed(seed)59                60        print('Parsed Prompt:', new_text)61        62        return ([[clip.encode(new_text), {}]], )63 64NODE_CLASS_MAPPINGS = {65    "CLIPTextEncode (NSP)": WAS_NSP_CLIPTextEncoder66}67