Skip to content

Latest commit

 

History

History
57 lines (38 loc) · 1.27 KB

README.md

File metadata and controls

57 lines (38 loc) · 1.27 KB

stable-diffusion-es

This is an ES module for Node.js that provides uses Stable Diffusion to generate images from a given prompt using AI.

Installation

npm install stable-diffusion-es

Usage

import { generate } from 'stable-diffusion-es';
import fs from 'fs';

const prompt = "A black cat";

generate(prompt)
    .then((response) => {
        if (!response) {
            console.log("There was an error generating the image.");
        } else {
            const filePath = './image.jpg';
            fs.writeFileSync(filePath, response); 
            console.log("Image generated successfully!");
            console.log(`Image saved at: ${filePath}`);
        }
    })
    .catch((error) => {
        console.error('Error:', error);
    });

A trick to get better images is to add:

{enhanced}

at the end of your prompt.

Make sure you have

"type": "module"

in your package.json file.

Output

A black cat