Skip to content

Phantom8015/stable-diffusion-es

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 AI from 'stable_diffusion-es';
import fs from 'fs';

let prompt = "A cat"

 AI.generate(prompt, async (result) => {
    if (result.error) {
        console.log(result.error)
        return;
    }
    try {
        for (let i = 0; i < result.results.length; i++) {
            let data = result.results[i].split(",")[1]
            const buffer = Buffer.from(data, "base64")
            const filename = `image_${i + 1}.png`
            fs.writeFileSync(filename, buffer)
        }
    } catch (e) {
        console.log(e)
    }
})

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 cat

About

Stable diffusion ES module for Node JS

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published