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

The default name of stable_diffusion sampler_index has been changed #4717

Closed
4 tasks done
BillDowney opened this issue May 28, 2024 · 1 comment · Fixed by #4798
Closed
4 tasks done

The default name of stable_diffusion sampler_index has been changed #4717

BillDowney opened this issue May 28, 2024 · 1 comment · Fixed by #4798
Labels
🐞 bug Something isn't working

Comments

@BillDowney
Copy link

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.9

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

DRAW_TEXT_OPTIONS.sampler_index in the stable_diffuse.py file, where the default name is "DPM++ SDE Karras", However, the sd webui has changed its default name to "DPM++ SDE" in the last 2024.3.24 commit record, so the api access has been unsuccessful.
It is recommended to remove the sampler_index key and use the default sd value when passing empty values

✔️ Expected Behavior

The sd tool should be called successfully

❌ Actual Behavior

sd tool call should fail

@dosubot dosubot bot added the 🐞 bug Something isn't working label May 28, 2024
Copy link

dosubot bot commented May 28, 2024

Hey @BillDowney, I'm here to help you with any bugs, questions, or contributions you might have for the repository. Let's work together to solve this issue.

To resolve the issue with the sampler_index key in the stable_diffuse.py file for Dify version 0.6.9, you can follow these steps:

  1. Remove the sampler_index key from the DRAW_TEXT_OPTIONS dictionary.
  2. Ensure that the sampler_name is not set explicitly in the draw_options dictionary if it is empty.

Here is the modified code:

# Remove 'sampler_index' from DRAW_TEXT_OPTIONS
DRAW_TEXT_OPTIONS = {
    "prompt": "",
    "negative_prompt": "",
    "seed": -1,
    "subseed": -1,
    "subseed_strength": 0,
    "seed_resize_from_h": -1,
    "seed_resize_from_w": -1,
    "batch_size": 1,
    "n_iter": 1,
    "steps": 10,
    "cfg_scale": 7,
    "width": 1024,
    "height": 1024,
    "restore_faces": False,
    "do_not_save_samples": False,
    "do_not_save_grid": False,
    "eta": 0,
    "denoising_strength": 0,
    "s_min_uncond": 0,
    "s_churn": 0,
    "s_tmax": 0,
    "s_tmin": 0,
    "s_noise": 0,
    "override_settings": {},
    "override_settings_restore_afterwards": True,
    "refiner_switch_at": 0,
    "disable_extra_networks": False,
    "comments": {},
    "enable_hr": False,
    "firstphase_width": 0,
    "firstphase_height": 0,
    "hr_scale": 2,
    "hr_second_pass_steps": 0,
    "hr_resize_x": 0,
    "hr_resize_y": 0,
    "hr_prompt": "",
    "hr_negative_prompt": "",
    "script_args": [],
    "send_images": True,
    "save_images": False,
    "alwayson_scripts": {}
}

# Modify the text2img method to handle empty sampler_name
def text2img(self, base_url: str, lora: str, prompt: str, negative_prompt: str, width: int, height: int, steps: int, model: str) \
    -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
    """
        generate image
    """
    # copy draw options
    draw_options = deepcopy(DRAW_TEXT_OPTIONS)

    if lora:
        draw_options['prompt'] = f'{lora},{prompt}'
    else:
        draw_options['prompt'] = prompt

    draw_options['width'] = width
    draw_options['height'] = height
    draw_options['steps'] = steps
    draw_options['negative_prompt'] = negative_prompt
    draw_options['override_settings']['sd_model_checkpoint'] = model

    # Ensure sampler_name is not set if empty
    if 'sampler_name' in draw_options and not draw_options['sampler_name']:
        del draw_options['sampler_name']

    try:
        url = str(URL(base_url) / 'sdapi' / 'v1' / 'txt2img')
        response = post(url, data=json.dumps(draw_options), timeout=120)
        if response.status_code != 200:
            return self.create_text_message('Failed to generate image')
        
        image = response.json()['images'][0]

        return self.create_blob_message(blob=b64decode(image), 
                                        meta={ 'mime_type': 'image/png' },
                                        save_as=self.VARIABLE_KEY.IMAGE.value)
        
    except Exception as e:
        return self.create_text_message('Failed to generate image')

This modification ensures that the sampler_index key is removed and the default SD value is used when passing empty values, resolving the API access failure caused by the SD WebUI's change in the default sampler name [1].

Details

About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
1 participant