dify icon indicating copy to clipboard operation
dify copied to clipboard

Bug in the tool Stable Diffusion webui

Open insistence-essenn opened this issue 1 year ago • 1 comments

Self Checks

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

Dify version

0.6.8

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I used the stable diffusion webui tool in workflow and I was not getting any output from the tool Solved this Issue by changing this in api/core/tools/provider/builtin/stablediffusion/tools/stable_difussion.py: DRAW_TEXT_OPTIONS = { "prompt": "", "negative_prompt": "", "seed": -1, "subseed": -1, "subseed_strength": 0, "seed_resize_from_h": -1, 'sampler_index': 'DPM++ SDE Karras', "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": {} } to this: 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": {} }

✔️ Expected Behavior

Get an Image

❌ Actual Behavior

Through an error.

insistence-essenn avatar May 22 '24 18:05 insistence-essenn

To resolve the error thrown by the Stable Diffusion webui tool after modifying the DRAW_TEXT_OPTIONS dictionary, ensure that the modifications you made are correctly reflected in the code where draw_options is used. Specifically, make sure that any new keys you added to DRAW_TEXT_OPTIONS are properly handled in the text2img and img2img methods.

Here is an example of how you can ensure the draw_options dictionary is correctly populated:

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 any new keys are handled here
    # For example, if you added a new key 'new_option' in DRAW_TEXT_OPTIONS
    # draw_options['new_option'] = some_value

    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')

Ensure that any new keys you added to DRAW_TEXT_OPTIONS are correctly set in the draw_options dictionary before making the API call. This will help in resolving the error.

Additionally, you can check the specific error logs or stack traces generated by the Stable Diffusion webui tool to gain more insight into the root cause of the error. If you continue to experience issues, please provide the specific error message or stack trace you are encountering, as this will help in further diagnosing the problem.

Details

Sources


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.

dosubot[bot] avatar May 22 '24 18:05 dosubot[bot]

how to use img2img why image_id: is empty image_variable:type=<ToolRuntimeVariableType.IMAGE: 'image'> name='image' position=0 tool_name='stable_diffusion' value='aac04d0b-12a2-4848-a018-27c73b86a35a'

frenude avatar Jun 06 '24 06:06 frenude