diff --git a/README.md b/README.md index c25154e..1c7e962 100644 --- a/README.md +++ b/README.md @@ -1 +1,78 @@ # ClipStuff +## Basic Instructions. + +Pass CLIP output from Load Checkpoint into SpecialClipLoader node, then use the outputted clip with standard Clip Text Encode. + +See example workflow in examples folder. + +### Example Photo +![Example Photo](assets/first_example.png) + +## Functions + +## Syntax Elements + +1. **Embedding**: + - Syntax: `embedding:WORD` + - Example: `embedding:face_vector` + - Represents a named vector embedding(Textual Inversion). + +2. **Word**: + - Syntax: Any alphanumeric word including characters such as `,`, `_`, and `-`. + - Example: `cat, dog_face, id_123` + - Represents simple words or identifiers. + +3. **Quoted String**: + - Syntax: A string enclosed within double or single quotes. You can escape quotes inside the string using a backslash (`\`). + - Example: `"Hello World"`, `'It\'s a sunny day'` + - Represents string literals. + +## Functions + +Here are the available functions and their usage: + +1. **Sum Function**: + - Syntax: `sum(arg1 | arg2 | ... | argN)` + - Adds together multiple embeddings. + - Example: `sum(embedding:face1 | dog)` + +2. **Negation Function**: + - Syntax: `neg(arg)` + - Negates the output. + - Example: `neg(A embedding:happycats outside)` + +3. **Normalization Function**: + - Syntax: `norm(arg)` + - Normalizes the given vector embedding. + - Example: `norm(sum(embedding:face1 | embedding:face2))` + +4. **Difference Function**: + - Syntax: `diff(arg1 | arg2 | ... | argN)` + - Computes the difference between multiple vector embeddings. + - Example: `diff(embedding:face1 | embedding:face2)` + +### Notes on Arguments: +- Each function takes one or more arguments. +- An argument (`arg`) can be an embedding, a word, another function, or a quoted string. +- For functions that accept multiple arguments, they are separated by the `|` symbol. + +## Examples + +1. Add two embeddings and normalize the result: + ``` + norm(sum(cat | dog | horse | parrot)) + ``` + +2. Negate an embedding: + ``` + neg(embedding:body_vector) + ``` + +3. King - Man + Women = Queen: + ``` + sum(diff(king|man)|queen) + ``` + or + ``` + sum(king|neg(man)|queen) + ``` diff --git a/assets/first_example.png b/assets/first_example.png new file mode 100644 index 0000000..c620f0e Binary files /dev/null and b/assets/first_example.png differ diff --git a/examples/WIP_Example_workflow.json b/examples/WIP_Example_workflow.json new file mode 100644 index 0000000..88652ba --- /dev/null +++ b/examples/WIP_Example_workflow.json @@ -0,0 +1,1385 @@ +{ + "last_node_id": 36, + "last_link_id": 59, + "nodes": [ + { + "id": 17, + "type": "PreviewImage", + "pos": [ + 1582, + 656 + ], + "size": { + "0": 560.5368041992188, + "1": 595.4229125976562 + }, + "flags": {}, + "order": 20, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 19 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 18, + "type": "VAEDecode", + "pos": [ + 1363, + 656 + ], + "size": { + "0": 210, + "1": 46 + }, + "flags": {}, + "order": 16, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 21 + }, + { + "name": "vae", + "type": "VAE", + "link": 20 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 19 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + } + }, + { + "id": 12, + "type": "CLIPTextEncode", + "pos": [ + 1169.8889425109312, + 741 + ], + "size": [ + 403.1110574890688, + 81.1019947779863 + ], + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 14 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 22 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "A beautiful photo of a sum(king|neg(man)|women)" + ] + }, + { + "id": 13, + "type": "CLIPTextEncode", + "pos": [ + 1170.4677016854578, + 876 + ], + "size": [ + 402.53229831454223, + 76.00000286102295 + ], + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 15 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 23 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "sum(blurry|bad|ruined) diff(black|photo) and diff(white|photo)" + ] + }, + { + "id": 23, + "type": "VAEDecode", + "pos": [ + 320, + 27 + ], + "size": { + "0": 210, + "1": 46 + }, + "flags": {}, + "order": 17, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 33 + }, + { + "name": "vae", + "type": "VAE", + "link": 34 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 32 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + } + }, + { + "id": 28, + "type": "VAEDecode", + "pos": [ + 320, + 656 + ], + "size": { + "0": 210, + "1": 46 + }, + "flags": {}, + "order": 18, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 42 + }, + { + "name": "vae", + "type": "VAE", + "link": 43 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 41 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + } + }, + { + "id": 4, + "type": "CheckpointLoaderSimple", + "pos": [ + 2153, + 32 + ], + "size": { + "0": 315, + "1": 98 + }, + "flags": {}, + "order": 0, + "mode": 0, + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 25, + 28, + 37, + 46 + ], + "slot_index": 0 + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 11 + ], + "slot_index": 1 + }, + { + "name": "VAE", + "type": "VAE", + "links": [ + 20, + 34, + 43, + 51 + ], + "slot_index": 2 + } + ], + "properties": { + "Node name for S&R": "CheckpointLoaderSimple" + }, + "widgets_values": [ + "realisticVisionV13_v13.safetensors" + ] + }, + { + "id": 29, + "type": "CLIPTextEncode", + "pos": [ + 1166.8889465332031, + 110 + ], + "size": { + "0": 403.1110534667969, + "1": 81.10199737548828 + }, + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 44 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 47 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "A beautiful photo of a sum(king|neg(man))" + ] + }, + { + "id": 30, + "type": "CLIPTextEncode", + "pos": [ + 1167.4677124023438, + 240 + ], + "size": { + "0": 402.53228759765625, + "1": 76 + }, + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 45 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 48 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "blurry" + ] + }, + { + "id": 33, + "type": "VAEDecode", + "pos": [ + 1360, + 27 + ], + "size": { + "0": 210, + "1": 46 + }, + "flags": {}, + "order": 19, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 50 + }, + { + "name": "vae", + "type": "VAE", + "link": 51 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 49 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + } + }, + { + "id": 32, + "type": "PreviewImage", + "pos": [ + 1580, + 27 + ], + "size": { + "0": 560.5368041992188, + "1": 595.4229125976562 + }, + "flags": {}, + "order": 23, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 49 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 11, + "type": "Special CLIP Loader", + "pos": [ + 2507, + 45 + ], + "size": { + "0": 210, + "1": 26 + }, + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ + { + "name": "source_clip", + "type": "CLIP", + "link": 11 + } + ], + "outputs": [ + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 14, + 15, + 26, + 27, + 35, + 36, + 44, + 45 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "Special CLIP Loader" + } + }, + { + "id": 24, + "type": "CLIPTextEncode", + "pos": [ + 130, + 741 + ], + "size": { + "0": 403.1110534667969, + "1": 81.10199737548828 + }, + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 35 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 38 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "A beautiful photo of a sum(king|neg(man)|women)" + ] + }, + { + "id": 25, + "type": "CLIPTextEncode", + "pos": [ + 130, + 876 + ], + "size": { + "0": 402.53228759765625, + "1": 76.00000762939453 + }, + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 36 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 39 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "blurry" + ] + }, + { + "id": 26, + "type": "KSampler", + "pos": [ + 220, + 989.4229125976562 + ], + "size": { + "0": 315, + "1": 262 + }, + "flags": {}, + "order": 14, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 37 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 38 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 39 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 54 + }, + { + "name": "seed", + "type": "INT", + "link": 58, + "widget": { + "name": "seed", + "config": [ + "INT", + { + "default": 0, + "min": 0, + "max": 18446744073709552000 + } + ] + }, + "slot_index": 4 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 42 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "KSampler" + }, + "widgets_values": [ + 565760744384977, + "randomize", + 20, + 8, + "euler", + "normal", + 1 + ] + }, + { + "id": 27, + "type": "PreviewImage", + "pos": [ + 540, + 656 + ], + "size": { + "0": 560.5368041992188, + "1": 595.4229125976562 + }, + "flags": {}, + "order": 22, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 41 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 19, + "type": "CLIPTextEncode", + "pos": [ + 126.88894653320312, + 110 + ], + "size": { + "0": 403.1110534667969, + "1": 81.10199737548828 + }, + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 26 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 29 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "A beautiful photo of a king" + ] + }, + { + "id": 20, + "type": "CLIPTextEncode", + "pos": [ + 127.46771240234375, + 240 + ], + "size": { + "0": 402.53228759765625, + "1": 76 + }, + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 27 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 30 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "blurry" + ] + }, + { + "id": 21, + "type": "KSampler", + "pos": [ + 215, + 360 + ], + "size": { + "0": 315, + "1": 262 + }, + "flags": {}, + "order": 13, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 28 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 29 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 30 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 55 + }, + { + "name": "seed", + "type": "INT", + "link": 59, + "widget": { + "name": "seed", + "config": [ + "INT", + { + "default": 0, + "min": 0, + "max": 18446744073709552000 + } + ] + }, + "slot_index": 4 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 33 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "KSampler" + }, + "widgets_values": [ + 931519768068444, + "randomize", + 20, + 8, + "euler", + "normal", + 1 + ] + }, + { + "id": 22, + "type": "PreviewImage", + "pos": [ + 540, + 27 + ], + "size": { + "0": 560.5368041992188, + "1": 595.4229125976562 + }, + "flags": {}, + "order": 21, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 32 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 14, + "type": "KSampler", + "pos": [ + 1258, + 989 + ], + "size": [ + 315, + 262 + ], + "flags": {}, + "order": 12, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 25 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 22 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 23 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 53 + }, + { + "name": "seed", + "type": "INT", + "link": 57, + "widget": { + "name": "seed", + "config": [ + "INT", + { + "default": 0, + "min": 0, + "max": 18446744073709552000 + } + ] + }, + "slot_index": 4 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 21 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "KSampler" + }, + "widgets_values": [ + 981858320026741, + "randomize", + 20, + 8, + "euler", + "normal", + 1 + ] + }, + { + "id": 31, + "type": "KSampler", + "pos": [ + 1255, + 360 + ], + "size": { + "0": 315, + "1": 262 + }, + "flags": {}, + "order": 15, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 46 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 47 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 48 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 52 + }, + { + "name": "seed", + "type": "INT", + "link": 56, + "widget": { + "name": "seed", + "config": [ + "INT", + { + "default": 0, + "min": 0, + "max": 18446744073709552000 + } + ] + }, + "slot_index": 4 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 50 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "KSampler" + }, + "widgets_values": [ + 233087233452632, + "randomize", + 20, + 8, + "euler", + "normal", + 1 + ] + }, + { + "id": 36, + "type": "EmptyLatentImage", + "pos": [ + 2478, + 145 + ], + "size": { + "0": 315, + "1": 106 + }, + "flags": {}, + "order": 1, + "mode": 0, + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 52, + 53, + 54, + 55 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "EmptyLatentImage" + }, + "widgets_values": [ + 512, + 512, + 1 + ] + }, + { + "id": 35, + "type": "PrimitiveNode", + "pos": [ + 2493, + 333 + ], + "size": { + "0": 210, + "1": 82 + }, + "flags": {}, + "order": 2, + "mode": 0, + "outputs": [ + { + "name": "INT", + "type": "INT", + "links": [ + 56, + 57, + 58, + 59 + ], + "slot_index": 0, + "widget": { + "name": "seed", + "config": [ + "INT", + { + "default": 0, + "min": 0, + "max": 18446744073709552000 + } + ] + } + } + ], + "properties": {}, + "widgets_values": [ + 24566375658893, + "fixed" + ] + } + ], + "links": [ + [ + 11, + 4, + 1, + 11, + 0, + "CLIP" + ], + [ + 14, + 11, + 0, + 12, + 0, + "CLIP" + ], + [ + 15, + 11, + 0, + 13, + 0, + "CLIP" + ], + [ + 19, + 18, + 0, + 17, + 0, + "IMAGE" + ], + [ + 20, + 4, + 2, + 18, + 1, + "VAE" + ], + [ + 21, + 14, + 0, + 18, + 0, + "LATENT" + ], + [ + 22, + 12, + 0, + 14, + 1, + "CONDITIONING" + ], + [ + 23, + 13, + 0, + 14, + 2, + "CONDITIONING" + ], + [ + 25, + 4, + 0, + 14, + 0, + "MODEL" + ], + [ + 26, + 11, + 0, + 19, + 0, + "CLIP" + ], + [ + 27, + 11, + 0, + 20, + 0, + "CLIP" + ], + [ + 28, + 4, + 0, + 21, + 0, + "MODEL" + ], + [ + 29, + 19, + 0, + 21, + 1, + "CONDITIONING" + ], + [ + 30, + 20, + 0, + 21, + 2, + "CONDITIONING" + ], + [ + 32, + 23, + 0, + 22, + 0, + "IMAGE" + ], + [ + 33, + 21, + 0, + 23, + 0, + "LATENT" + ], + [ + 34, + 4, + 2, + 23, + 1, + "VAE" + ], + [ + 35, + 11, + 0, + 24, + 0, + "CLIP" + ], + [ + 36, + 11, + 0, + 25, + 0, + "CLIP" + ], + [ + 37, + 4, + 0, + 26, + 0, + "MODEL" + ], + [ + 38, + 24, + 0, + 26, + 1, + "CONDITIONING" + ], + [ + 39, + 25, + 0, + 26, + 2, + "CONDITIONING" + ], + [ + 41, + 28, + 0, + 27, + 0, + "IMAGE" + ], + [ + 42, + 26, + 0, + 28, + 0, + "LATENT" + ], + [ + 43, + 4, + 2, + 28, + 1, + "VAE" + ], + [ + 44, + 11, + 0, + 29, + 0, + "CLIP" + ], + [ + 45, + 11, + 0, + 30, + 0, + "CLIP" + ], + [ + 46, + 4, + 0, + 31, + 0, + "MODEL" + ], + [ + 47, + 29, + 0, + 31, + 1, + "CONDITIONING" + ], + [ + 48, + 30, + 0, + 31, + 2, + "CONDITIONING" + ], + [ + 49, + 33, + 0, + 32, + 0, + "IMAGE" + ], + [ + 50, + 31, + 0, + 33, + 0, + "LATENT" + ], + [ + 51, + 4, + 2, + 33, + 1, + "VAE" + ], + [ + 52, + 36, + 0, + 31, + 3, + "LATENT" + ], + [ + 53, + 36, + 0, + 14, + 3, + "LATENT" + ], + [ + 54, + 36, + 0, + 26, + 3, + "LATENT" + ], + [ + 55, + 36, + 0, + 21, + 3, + "LATENT" + ], + [ + 56, + 35, + 0, + 31, + 4, + "INT" + ], + [ + 57, + 35, + 0, + 14, + 4, + "INT" + ], + [ + 58, + 35, + 0, + 26, + 4, + "INT" + ], + [ + 59, + 35, + 0, + 21, + 4, + "INT" + ] + ], + "groups": [], + "config": {}, + "extra": {}, + "version": 0.4 +} \ No newline at end of file