Fooocus icon indicating copy to clipboard operation
Fooocus copied to clipboard

Add Array Support on main prompt

Open flannerybh opened this issue 1 year ago • 2 comments

Idea to use arrays in the main prompt.
To use arrays, put all values inside double brackets. For example: [[tall, short, fat, thin]] man. would produce 4 images (tall man, short man, fat man, thin man). You also need to set your number of images to map, if you set the number of images higher, the array will just wrap around.

You can also use multiple arrays for example: [[beautiful, ugly]] [[man, woman]] wearing a [[red, white, blue]] suit would produce all combinations of each array (you'd need to set the image count to 12).

This can be used in conjunction with the "Freeze Seed" checkbox, so each image uses the same random seed so your images will look very similar except for the differences that come from the words in the array.

flannerybh avatar Dec 19 '23 12:12 flannerybh

What is the difference between it and wildcards?

xhoxye avatar Dec 20 '23 05:12 xhoxye

What is the difference between it and wildcards?

A wild card is chosen at random. There's not guarantee that you would cycle through them all, or that you wouldn't use the same value twice. An array will deterministically cycle through all values.

It's also much quicker to use arrays because they can be added/edited right in the prompt rather than in a config file.

flannerybh avatar Dec 20 '23 12:12 flannerybh

@lllyasviel , just wanted to check if this was on your radar. This is my first contribution, let me know if there's something else I should do to move it along. Or if you're not interested in pulling.

Thanks!

flannerybh avatar Jan 06 '24 13:01 flannerybh

Hi Guys, can this be please reviewed/merged so we can start using this amazing feature.

CraigOndrak avatar Jan 06 '24 15:01 CraigOndrak

@mashb1t is there anything I can do to get this approved/merged. Looks like a few people are interested.

flannerybh avatar Jan 10 '24 19:01 flannerybh

@flanneryhbh as much as i'd also want to see this feature merged there is nothing we can do. The Fooocus core dev team will be back mid/end of January, see update_log.md

(2023 Dec 21) Hi all, the feature updating of Fooocus will be paused for about two or three weeks because we have some other workloads. See you soon and we will come back in mid or late Jan. However, you may still see updates if other collaborators are fixing bugs or solving problems.

mashb1t avatar Jan 10 '24 19:01 mashb1t

I've given it a test and it works as advertised, awesome. Just what I wanted.

A nice extra feature would be some sort of auto image number setting. I would be handy if there was a checkbox to mean it would automatically run the number of images to match the number of combinations.

I guess it might be good if the Generate button told you how many images it was about to create "Generate 12 images". But I'm guessing that would involve changing when the prompt is parsed, I've not really looked at the code in any detail yet.

And a clearly much more involved feature would be to have a label under the output images showing you the array combinations used for that image.

andynormancx avatar Jan 15 '24 21:01 andynormancx

Idea to use arrays in the main prompt. To use arrays, put all values inside double brackets. For example: [[tall, short, fat, thin]] man. would produce 4 images (tall man, short man, fat man, thin man). You also need to set your number of images to map, if you set the number of images higher, the array will just wrap around.

You can also use multiple arrays for example: [[beautiful, ugly]] [[man, woman]] wearing a [[red, white, blue]] suit would produce all combinations of each array (you'd need to set the image count to 12).

This can be used in conjunction with the "Freeze Seed" checkbox, so each image uses the same random seed so your images will look very similar except for the differences that come from the words in the array.

Perhaps it makes sense to use a syntax that is also used in other systems. Then you can use prompts more easily in different systems without having to modify them too much.

In ComfyUi the syntax is like this: {red|blue|yellow|green}

In Automatic1111 the same, but without brackets: red|blue|yellow|green

almfisch avatar Jan 19 '24 20:01 almfisch

This doesnt seem to be working in the current version.

Ev-Bro avatar Jan 28 '24 16:01 Ev-Bro

Idea to use arrays in the main prompt. To use arrays, put all values inside double brackets. For example: [[tall, short, fat, thin]] man. would produce 4 images (tall man, short man, fat man, thin man). You also need to set your number of images to map, if you set the number of images higher, the array will just wrap around. You can also use multiple arrays for example: [[beautiful, ugly]] [[man, woman]] wearing a [[red, white, blue]] suit would produce all combinations of each array (you'd need to set the image count to 12). This can be used in conjunction with the "Freeze Seed" checkbox, so each image uses the same random seed so your images will look very similar except for the differences that come from the words in the array.

Perhaps it makes sense to use a syntax that is also used in other systems. Then you can use prompts more easily in different systems without having to modify them too much.

In ComfyUi the syntax is like this: {red|blue|yellow|green}

In Automatic1111 the same, but without brackets: red|blue|yellow|green

The pipe (|) notation in ComfyUi and Automatic1111 seem to be a wildcard system, where it picks a random value from the list. The array concept is deterministic, as it will cycle through the values in order. I think that's a way better feature. I'll leave the wildcard notation free for someone else to implement.

flannerybh avatar Jan 28 '24 19:01 flannerybh

I’ve made my own additional changes to this to make it more flexible. They allow it to be used for applying arrays to prompt weighting for example. And also to be able to have an empty value as one of the array elements.

Not sure what the proper way of contributing this would be, I’m not up to speed on the workflow of PRs on public GitHub repos.

andynormancx avatar Jan 29 '24 11:01 andynormancx

@andynormancx you can make a PR to https://github.com/flanneryhbh/Fooocus-add-array-to-propt/tree/main so your changes will be reflected in this PR if @flanneryhbh accepts them.

mashb1t avatar Jan 29 '24 12:01 mashb1t

This doesnt seem to be working in the current version.

@Ev-Bro this feature is still in a Pull Request, meaning it's not in the current base version of Fooocus. If you are having trouble getting it to work in my forked branch, please elaborate.

flannerybh avatar Jan 29 '24 12:01 flannerybh

This doesnt seem to be working in the current version.

@Ev-Bro this feature is still in a Pull Request, meaning it's not in the current base version of Fooocus. If you are having trouble getting it to work in my forked branch, please elaborate.

My bad! Please ignore.

Ev-Bro avatar Jan 29 '24 20:01 Ev-Bro

This doesnt seem to be working in the current version.

@Ev-Bro this feature is still in a Pull Request, meaning it's not in the current base version of Fooocus. If you are having trouble getting it to work in my forked branch, please elaborate.

My bad! Please ignore.

@flanneryhbh This feature is merged on the other branch version and adds the ability to group words with wildcards,thanks! https://github.com/metercai/SimpleSDXL

metercai avatar Feb 17 '24 20:02 metercai