prompt_image_generation_task

Bases: BaseImageGenerationTask

Attributes

NameTypeDescription
image_generation_driverBaseImageGenerationDriverThe engine used to generate the image.
negative_rulesetslist[Ruleset]List of negatively-weighted rulesets applied to the text prompt, if supported by the driver.
negative_ruleslist[Rule]List of negatively-weighted rules applied to the text prompt, if supported by the driver.
output_dirOptional[str]If provided, the generated image will be written to disk in output_dir.
output_fileOptional[str]If provided, the generated image will be written to disk as output_file.
Source Code in griptape/tasks/prompt_image_generation_task.py
@define
class PromptImageGenerationTask(BaseImageGenerationTask):
    """Used to generate an image from a text prompt.

    Accepts prompt as input in one of the following formats:
    - template string
    - TextArtifact
    - Callable that returns a TextArtifact.

    Attributes:
        image_generation_driver: The engine used to generate the image.
        negative_rulesets: List of negatively-weighted rulesets applied to the text prompt, if supported by the driver.
        negative_rules: List of negatively-weighted rules applied to the text prompt, if supported by the driver.
        output_dir: If provided, the generated image will be written to disk in output_dir.
        output_file: If provided, the generated image will be written to disk as output_file.
    """

    DEFAULT_INPUT_TEMPLATE = "{{ args[0] }}"

    _input: Union[str, TextArtifact, Callable[[BaseTask], TextArtifact]] = field(
        default=DEFAULT_INPUT_TEMPLATE, alias="input"
    )

    @property
    def input(self) -> TextArtifact:
        if isinstance(self._input, TextArtifact):
            return self._input
        if isinstance(self._input, Callable):
            return self._input(self)
        return TextArtifact(J2().render_from_string(self._input, **self.full_context))

    @input.setter
    def input(self, value: TextArtifact) -> None:
        self._input = value

    def try_run(self) -> ImageArtifact:
        image_artifact = self.image_generation_driver.run_text_to_image(
            prompts=self._get_prompts(self.input.to_text()),
            negative_prompts=self._get_negative_prompts(),
        )

        if self.output_dir or self.output_file:
            self._write_to_file(image_artifact)

        return image_artifact
  • DEFAULT_INPUT_TEMPLATE = '{{ args[0] }}' class-attribute instance-attribute

  • _input = field(default=DEFAULT_INPUT_TEMPLATE, alias='input') class-attribute instance-attribute

  • input property writable

try_run()

Source Code in griptape/tasks/prompt_image_generation_task.py
def try_run(self) -> ImageArtifact:
    image_artifact = self.image_generation_driver.run_text_to_image(
        prompts=self._get_prompts(self.input.to_text()),
        negative_prompts=self._get_negative_prompts(),
    )

    if self.output_dir or self.output_file:
        self._write_to_file(image_artifact)

    return image_artifact

Could this page be better? Report a problem or suggest an addition!