├── README.md └── stablediffusionapi ├── package.json ├── pics ├── 1.png ├── 2.png └── 3.png └── stablegenerate.js /README.md: -------------------------------------------------------------------------------- 1 | # Stable-Diffusion-API-NodeJS-AI-ImageGenerator 2 | An API NodeJS script to automate image generation using Stable Diffusion AI Image Generator 3 | 4 | 5 | ## 6 |

Subscribe to my Youtube! Net2Dev

7 | 8 | 9 | 10 | 11 | 12 | ** THE FILES ATTACHED TO THIS REPO ARE FOR EDUCATIONAL PURPOSES ONLY ** 13 | ** USE IT AT YOUR OWN RISK** **I'M NOT RESPONSIBLE FOR ANY USE, ISSUES ETC.. ** 14 | 15 | 16 | ## Step 1 17 | 18 | Download stablediffusionapi folder from this repo. 19 | 20 | ## Step 2 21 | 22 | Extract and navigate to project folder then install dependencies: npm i 23 | 24 | ```shell 25 | cd stablediffusionapi 26 | npm i 27 | ``` 28 | ## Step 3 29 | 30 | Create your Account in Stablediffusion: https://stablediffusionapi.com/ 31 | 32 | ## Step 4 33 | 34 | Create API key then copy it. 35 | Update stablegenerate.js and add your api key: 36 | 37 | ```shell 38 | const apiKey = 'REPLACE-WITH-YOUR-API-KEY'; 39 | ``` 40 | 41 | ## Step 5 42 | 43 | Add your prompt description of what you want to generate. 44 | 45 | ```shell 46 | const prompt = 'a dog walking on the beach with sunglasses, portrait, ultra realistic, futuristic background , concept art, intricate details, highly detailed'; 47 | ``` 48 | 49 | ## Step 6 50 | 51 | Add how many pics you want to generate: 52 | 53 | ```shell 54 | const numberOfPics = '3' 55 | ``` 56 | 57 | ## Step 7 58 | - Save and execute in your terminal: 59 | 60 | ```shell 61 | node stablegenerate.js 62 | ``` 63 | 64 | Pictures will be inside the "pics" folder once generated. 65 | 66 | Follow me in Youtube @Net2Dev!! 67 | -------------------------------------------------------------------------------- /stablediffusionapi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "axios": "^1.3.4", 4 | "fs-extra": "^8.1.0", 5 | "node-fetch": "^2.6.1" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /stablediffusionapi/pics/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/net2devcrypto/Stable-Diffusion-API-NodeJS-AI-ImageGenerator/b3d97f278edb821cfe2e8a02ad754a73e146414d/stablediffusionapi/pics/1.png -------------------------------------------------------------------------------- /stablediffusionapi/pics/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/net2devcrypto/Stable-Diffusion-API-NodeJS-AI-ImageGenerator/b3d97f278edb821cfe2e8a02ad754a73e146414d/stablediffusionapi/pics/2.png -------------------------------------------------------------------------------- /stablediffusionapi/pics/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/net2devcrypto/Stable-Diffusion-API-NodeJS-AI-ImageGenerator/b3d97f278edb821cfe2e8a02ad754a73e146414d/stablediffusionapi/pics/3.png -------------------------------------------------------------------------------- /stablediffusionapi/stablegenerate.js: -------------------------------------------------------------------------------- 1 | const https = require("https"); 2 | const fs = require("fs"); 3 | const dir = './pics'; 4 | const axios = require('axios'); 5 | 6 | /* 7 | ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ 8 | █ ▄▄▀█ ▄▄█▄ ▄█ ▄ █ ▄▀█ ▄▄█▀███▀ 9 | █ ██ █ ▄▄██ ███▀▄█ █ █ ▄▄██ ▀ █ 10 | █▄██▄█▄▄▄██▄██ ▀▀█▄▄██▄▄▄███▄██ 11 | ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ 12 | Stable Diffusion AI Image Generator 13 | 14 | Steps, 15 | 16 | - In your terminal, navigate to project folder then install dependencies: npm i 17 | - Create your Account in Stablediffusion: https://stablediffusionapi.com/ 18 | - Create API key then add your key to the const "apiKey" below. 19 | - Add your prompt description. 20 | - Add how many pics you want 21 | - Save and execute in your terminal: 22 | 23 | node stablegenerate.js 24 | 25 | The generated art should be available in the "pics" folder. 26 | 27 | Update THIS INFO: 28 | */ 29 | const apiKey = 'REPLACE-WITH-YOUR-API-KEY'; 30 | const prompt = 'a dog walking on the beach with sunglasses, portrait, ultra realistic, futuristic background , concept art, intricate details, highly detailed'; 31 | const numberOfPics = '3' //Limitation of 4 maximum image generation per call observed. 32 | 33 | // CODE BEGIN! 34 | 35 | const stable = ` 36 | ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ 37 | █ ▄▄█▄ ▄█ ▄▄▀█ ▄▄▀█ ██ ▄▄█ ▄▀██▄██ ▄▄█ ▄▄█ ██ █ ▄▄██▄██▀▄▄▀█ ▄▄▀ 38 | █▄▄▀██ ██ ▀▀ █ ▄▄▀█ ██ ▄▄█ █ ██ ▄█ ▄██ ▄██ ██ █▄▄▀██ ▄█ ██ █ ██ 39 | █▄▄▄██▄██▄██▄█▄▄▄▄█▄▄█▄▄▄█▄▄██▄▄▄█▄███▄████▄▄▄█▄▄▄█▄▄▄██▄▄██▄██▄ 40 | ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ 41 | ` 42 | 43 | 44 | const bodyInfo = JSON.stringify( 45 | { 46 | "key": apiKey, 47 | "prompt": prompt , 48 | "negative_prompt": "((out of frame)), ((extra fingers)), mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), (((tiling))), ((naked)), ((tile)), ((fleshpile)), ((ugly)), (((abstract))), blurry, ((bad anatomy)), ((bad proportions)), ((extra limbs)), cloned face, (((skinny))), glitchy, ((extra breasts)), ((double torso)), ((extra arms)), ((extra hands)), ((mangled fingers)), ((missing breasts)), (missing lips), ((ugly face)), ((fat)), ((extra legs)), anime", 49 | "width": "512", 50 | "height": "512", 51 | "samples": numberOfPics, 52 | "num_inference_steps": "30", 53 | "safety_checker": "no", 54 | "enhance_prompt": "yes", 55 | "seed": null, 56 | "guidance_scale": 7.5, 57 | "webhook": null, 58 | "track_id": null 59 | }); 60 | 61 | const options = { 62 | headers: { 63 | "Content-Type": "application/json", 64 | }, 65 | }; 66 | 67 | async function generateArt() { 68 | console.log('') 69 | console.log(stable); 70 | console.log('') 71 | console.log('Generating Images....') 72 | console.log(''); 73 | const result = await axios.post('https://stablediffusionapi.com/api/v3/text2img', bodyInfo, options) 74 | const picAmount = result.data.output.length 75 | let i = 0; 76 | for (i; i < picAmount; i++) { 77 | let number = i + 1; 78 | getData(result.data.output[i], number + ".png"); 79 | console.log('Generated Pic ' + number); 80 | } 81 | } 82 | 83 | async function getData(image, filename) { 84 | await download(image, filename) 85 | } 86 | 87 | async function download(url, filename) { 88 | try { 89 | if (!fs.existsSync(dir)) { 90 | fs.mkdirSync(dir); 91 | } 92 | if (fs.existsSync(filename)) { 93 | return; 94 | } else { 95 | let request = https.get(url, function (response) { 96 | if (response.statusCode === 200) { 97 | let file = fs.createWriteStream(dir + '/' + filename); 98 | response.pipe(file); 99 | } 100 | request.setTimeout(12000, function () { 101 | request.abort(); 102 | }); 103 | }); 104 | } 105 | } catch (err) { 106 | console.error(err); 107 | } 108 | } 109 | 110 | 111 | generateArt(); --------------------------------------------------------------------------------