Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multi prompts #96

Merged
merged 2 commits into from
Jun 16, 2023
Merged

support multi prompts #96

merged 2 commits into from
Jun 16, 2023

Conversation

pythias
Copy link
Contributor

@pythias pythias commented Jun 12, 2023

p.prompt is list|str

@ototadana
Copy link
Owner

@pythias
Thanks for sending the PR!

I did not know that p.prompt could be a list. Thanks for letting me know. If you don't mind, could you please tell me the specific operation of the case where p.prompt becomes a list? Because I would like to see what problems the existing implementation causes and how it can be improved with this PR.

@pythias
Copy link
Contributor Author

pythias commented Jun 14, 2023

@ototadana When I want to generate multiple styles in one api request, like the script '/stable-diffusion-webui/scripts/prompt_matrix.py'

@ototadana
Copy link
Owner

@pythias
Thank you for your reply.

I apologize for my lack of understanding. Am I correct in understanding that this is a case of API calls only, not UI operations? And that you want to apply different prompts to each of the generated images?

If this understanding is correct, could you give me an example of a request for an API call, if you don't mind? I am quite interested in such a use case and would like to study it. (If this understanding is incorrect and could happen with UI operations, I would like to know the actual operation.)

Thank you.

@pythias
Copy link
Contributor Author

pythias commented Jun 15, 2023

@ototadana
Thank you for your reply.

You can call like this params

curl -X POST -H "Content-Type: application/json" 'https://127.0.0.1:7860/sdapi/v1/txt2img' -d '{"prompt":"winter|spring","script_name":"prompt matrix","script_args":[true,true,"positive","comma",10]}'

However, since the number of images returned by the face editor is twice the original number, it caused an error ( File "./stable-diffusion-webui/modules/images.py", line 179, in draw_grid_annotations assert cols == len(hor_texts), f'bad number of horizontal texts: {len(hor_texts)}; must be {cols}') when SD was drawing the grid. I remember that in a certain version, you provided the option to return only the final result.

谢谢你

@pythias
Copy link
Contributor Author

pythias commented Jun 15, 2023

@ototadana

In the extension I wrote, this is how I used it. I wrapped the original SD interface. When there are multiple style requests in the interface, I would modify the 'prompt' attribute in the StableDiffusionProcessing object.

def apply_multi_process(p: StableDiffusionProcessing):
    prompts = to_multi_prompts(p.prompt)
    if len(prompts) == 1:
        return
    
    processing.fix_seed(p)
    same_seed = get_extra_value(p, 'same-seed', False)

    p.prompt = prompts
    p.batch_size = 1
    p.n_iter = len(p.prompt)
    p.seed = [p.seed + (0 if same_seed else i) for i in range(len(p.prompt))]

https://github.com/pythias/sd-character-extension/blob/3475674df521e116de55d16c33b7432ac65c59a4/character/models.py#L171

@ototadana
Copy link
Owner

@pythias
Thank you very much for your detailed explanation. You have given me a better understanding of the issues.

What do you think of the following modification to the proc_images function?

        if type(p.prompt) == list:
            p.prompt = p.prompt[i]
        proc = self.proc_image(p, option, image)

If there is no problem with such a modification, I would be willing to implement a modification based on this on my end after merging this PR. (I'm thinking of perhaps a slightly pessimistic implementation that would work even if len(res.images) and len(p.prompt) do not match, similar to the treatment for p.seed and p.subseed.)

However, since the number of images returned by the face editor is twice the original number, it caused an error

Thank you. This is another issue. We will be adding new options to address this.

@pythias
Copy link
Contributor Author

pythias commented Jun 16, 2023

@ototadana
Your implement is better, thank you.

@ototadana
Copy link
Owner

@pythias
Thank you very much.

@ototadana ototadana merged commit 601efd0 into ototadana:main Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants