Captain is currently in ALPHA. We are happy to get your feedback
SDK
Use Comfyui

Module: use-comfyui

Table of contents

Functions

Functions

useComfyUI

useComfyUI(appId, onGenerated): Object

A hook to interact with the ComfyUI application. This hook manages the state of the image generation queue, interacts with the Stable Diffusion inventory, and handles message communication with the SDK.

Parameters

NameTypeDescription
appIdstringThe ID of the application using the ComfyUI.
onGenerated(image: string, meta: { filename: string ; subfolder: string }) => voidA callback function that gets called when an image is generated. It receives the generated image's temporary URL and metadata.

Returns

Object

  • An object containing the following properties and functions:
    • models: An object containing arrays of different model types (loras, checkpoints, vae, upscalers) from the Stable Diffusion inventory.
    • generate: A function to queue an image generation workflow.
    • isGenerating: A boolean indicating if an image is currently being generated.
    • image: A string URL of the currently generated image.
    • queueSize: A number indicating the current size of the image generation queue.

Example

const { models, generate, isGenerating, image, queueSize } = useComfyUI(appId, (image, meta) => {
  console.log("Generated image:", image, "with metadata:", meta);
});
 
// To generate an image:
generate("workflow_string_here");
 
// To access models:
console.log(models.loras, models.checkpoints, models.vae, models.upscalers);
 
// To check if an image is being generated:
console.log(isGenerating);
 
// To access the currently generated image:
console.log(image);
 
// To check the size of the generation queue:
console.log(queueSize);

Defined in

react/dist/esm/use-comfyui/index.js:41