bob_sd35.itti_node

Classes

ITTINode

Text & image to image generator node.

Functions

main([args])

Module Contents

class bob_sd35.itti_node.ITTINode

Bases: rclpy.node.Node

Text & image to image generator node.

_pipe = None
_cv_bridge
_prompt_sub
_image_pub
_prompt_callback(msg: std_msgs.msg.String)

Callback for incoming prompt messages. Parses JSON if message contains ‘role’ key, otherwise uses message as prompt.

_publish_image(pil_image: PIL.Image.Image)

Publishes a PIL Image as a ROS Image message if there are subscribers.

load_model()

Downloads the model if necessary and loads the SD3.5 Img2Img pipeline. Returns the loaded pipeline.

generate_image(prompt: str, input_image_path: str, output_path: str) PIL.Image.Image | None

Generates an image based on text prompt and an input image.

Args:

prompt: The text prompt describing the desired output. input_image_path: Path to the input image file. output_path: Path where the output image will be saved.

Returns:

The generated PIL Image if successful, None otherwise.

unload_model()

Unloads the model from memory to free VRAM.

_generate_auto_filename(output_path: str) str

Generates a unique filename when output_path ends with ‘auto’.

If output_path is ‘auto’ or ends with ‘/auto’, generates a filename with pattern: <base_path>itti_<4-digit-counter>_<8-char-random>.png

Args:

output_path: The output path parameter value.

Returns:

The generated unique filename, or original path if not ‘auto’.

_run_generation()

Runs the image generation using the configured parameters. If ‘once’ is True, shuts down the node after generation.

_schedule_shutdown(success: bool = True)

Schedules a shutdown after keep_alive seconds using a ROS2 timer. This is non-blocking and allows the executor to continue processing.

_shutdown_callback()

Timer callback that triggers the shutdown.

bob_sd35.itti_node.main(args=None)