Adieyal/sd-dynamic-prompts: A custom script for AUTOMATIC1111

Thank you.

I think

dynamic prompting is powerful tool for users to enjoy stable diffusion more convenient with creativity.
Do you have any plan to apply it for repo?
This work is a personal priority for me.

Hey @hihihi, I moved this to it’s own topic.

Very cool script.

Unfortunately scripts for AUTOMATIC1111’s repo are beyond the scope of this project, however, I think some of the ideas would be “relatively” easy to implement.

Architecturally, though, I don’t think docker-diffusers-api is the right place for this kind of logic (as a serverless project). I think it would make the most sense to handle all these combinations and permutations on the backend, and then request each individually generated prompt from docker-diffusers-api in parallel. This is really the kind of use-case where serverless GPU shines, and your user will get back all the results in record speed.

In any event, while this isn’t something I’ll be able to dedicate any resources to, and while I haven’t looked at the source code, there’s a good chance that the code could be adapted quite easily to run somewhere else, one stage earlier, i.e. wherever you call docker-diffusers-api from. Hope that makes sense! And hope you’ll have some luck with it :sweat_smile:

I agree that this should be done outside of banana.

you can do something like this

import re
import itertools

# print versions of a prompt using wild cards in curly braces, e.g. {a|b|c} -> a, b, c

text = "A {house|apartment|lodge|cottage} in {summer|winter|autumn|spring} by {artist1|artist2|artist3}"

def get_versions(text):
    # get all the wild cards
    wild_cards = re.findall(r"{(.*?)}", text)
    # print(wild_cards)
    # get all the options for each wild card
    options = [card.split("|") for card in wild_cards]
    # print(options)
    # get all the combinations of options
    combinations = list(itertools.product(*options))
    # print(combinations)
    # replace the wild cards with the combinations
    versions = []
    for combination in combinations:
        version = text
        for i, card in enumerate(wild_cards):
            version = version.replace("{" + card + "}", combination[i])
    return versions

print ("\n".join(get_versions(text)))
1 Like

@coffeeorgreentea, you legend! :star_struck:

Thanks so much for contributing this sample code :ok_hand: :pray:

1 Like