Git Product home page Git Product logo

comfy-ui-client's Introduction

ComfyUI Client

npm license

Node.js ComfyUI client based on the WebSockets API example.

See example in examples/generate.

Install

To install comfy-ui-client in an existing project:

npm install comfy-ui-client

Example Usage

import { ComfyUIClient } from 'comfy-ui-client';
import type { Prompt } from 'comfy-ui-client';

// Your prompt / workflow
const prompt: Prompt = {
    '3': {
        class_type: 'KSampler',
        inputs: {
            cfg: 8,
            denoise: 1,
            latent_image: ['5', 0],
            model: ['4', 0],
            negative: ['7', 0],
            positive: ['6', 0],
            sampler_name: 'euler',
            scheduler: 'normal',
            seed: 8566257,
            steps: 20,
        },
    },
    '4': {
        class_type: 'CheckpointLoaderSimple',
        inputs: {
            ckpt_name: 'v1-5-pruned-emaonly.cpkt',
        },
    },
    '5': {
        class_type: 'EmptyLatentImage',
        inputs: {
            batch_size: 1,
            height: 512,
            width: 512,
        },
    },
    '6': {
        class_type: 'CLIPTextEncode',
        inputs: {
            clip: ['4', 1],
            text: 'masterpiece best quality girl',
        },
    },
    '7': {
        class_type: 'CLIPTextEncode',
        inputs: {
            clip: ['4', 1],
            text: 'bad hands',
        },
    },
    '8': {
        class_type: 'VAEDecode',
        inputs: {
            samples: ['3', 0],
            vae: ['4', 2],
        },
    },
    '9': {
        class_type: 'SaveImage',
        inputs: {
            filename_prefix: 'ComfyUI',
            images: ['8', 0],
        },
    },
};

// Set the text prompt for our positive CLIPTextEncode
prompt['6'].inputs.text = 'masterpiece best quality man';

// Set the seed for our KSampler node
prompt['3'].inputs.seed = 5;

// Create client
const serverAddress = '127.0.0.1:8188';
const clientId = 'baadbabe-b00b-4206-9420-deadd00d1337';
const client = new ComfyUIClient(serverAddress, clientId);

// Connect to server
await client.connect();

// Generate images
const images = await client.getImages(prompt);

// Save images to file
const outputDir = './tmp/output';
await client.saveImages(images, outputDir);

// Disconnect
await client.disconnect();

License

This project is licensed under the MIT License.

comfy-ui-client's People

Contributors

itskaynine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

comfy-ui-client's Issues

Whether to consider Stream outputting images

Whether to consider Stream outputting images, storing images on the server and then uploading them to the image space, the operation will be too frequent, leading to server crashes

SyntaxError: Cannot use import statement outside a module

Not sure why this is happening, using the examples..

import { v4 as uuidv4 } from 'uuid';

import { ComfyUIClient } from 'comfy-ui-client';
import type { Prompt } from 'comfy-ui-client';

// The ComfyUI server address
const SERVER_ADDRESS = '127.0.0.1:8188';

export const txt2img = async (
prompt: Prompt,
outputDir: string,
): Promise => {
// Create client ID
const clientId = uuidv4();

// Create client
const client = new ComfyUIClient(SERVER_ADDRESS, clientId);

// Connect to server
await client.connect();

// Get images
const images = await client.getImages(prompt);

// Save images to file
await client.saveImages(images, outputDir);

// Disconnect
await client.disconnect();
};

ComfyUIClient websocket error when using https url

when using a free ngrok url to test my application, i kept getting the following errors.

{"level":30,"time":1720141565995,"pid":23720,"hostname":"DESKTOP","msg":"Connecting to url: ws://bc07-[public-ip].ngrok-free.app/ws?clientId=baadbabe-b00b-4206-9420-deadd00d1337"} 
{"level":50,"time":1720141566178,"pid":23720,"hostname":"DESKTOP","err":{"type":"Error","message":"Unexpected server response: 307","stack":"Error: Unexpected server response: 307\n at ClientRequest.<anony mous> 

i was able to fix this with a workaround by going into .\node_modules\comfy-ui-client\dist\index.js from inside my project and changing

const url = `ws://${this.serverAddress}/ws?clientId=${this.clientId}`;
into
const url = `wss://${this.serverAddress}/ws?clientId=${this.clientId}`;

but i dont think that editing the module itself from my project is a good solution, even though it worked for me this time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.