langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
48.67k stars 6.97k forks source link

Bug in the tool Stable Diffusion webui #4594

Closed insistence-essenn closed 3 months ago

insistence-essenn commented 5 months ago

Self Checks

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.

dosubot[bot] commented 5 months ago

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** - [api/core/tools/provider/builtin/stablediffusion/tools/stable_diffusion.py](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/builtin/stablediffusion/tools/stable_diffusion.py) - [en/tutorials/tool-configuration/stable-diffusion.md](https://github.com/langgenius/dify-docs/blob/main/en/tutorials/tool-configuration/stable-diffusion.md) - [api/core/tools/provider/builtin/stablediffusion/stablediffusion.yaml](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/builtin/stablediffusion/stablediffusion.yaml) - [en/getting-started/install-self-hosted/environments.md](https://github.com/langgenius/dify-docs/blob/main/en/getting-started/install-self-hosted/environments.md)
**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.

frenude commented 4 months ago

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'