node-sd-webui
Advanced tools
+11
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const txt2img_js_1 = require("./sdapi/txt2img.js"); | ||
| const sdwebui = (props) => { | ||
| const apiUrl = props?.apiUrl || 'http://localhost:7860'; | ||
| return { | ||
| apiUrl, | ||
| txt2img: (options) => (0, txt2img_js_1.txt2img)(options, apiUrl), | ||
| }; | ||
| }; | ||
| exports.default = sdwebui; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./txt2img"), exports); |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.txt2img = void 0; | ||
| const node_fetch_1 = __importDefault(require("node-fetch")); | ||
| const txt2img = async (options, apiUrl = 'http://localhost:7860') => { | ||
| let body = { | ||
| prompt: options.prompt, | ||
| negative_prompt: options.negativePrompt, | ||
| seed: options.seed, | ||
| subseed: options.variationSeed, | ||
| subseed_strength: options.variationSeedStrength, | ||
| sampler_name: options.samplingMethod, | ||
| batch_size: options.batchSize, | ||
| n_iter: options.batchCount, | ||
| steps: options.steps, | ||
| width: options.width, | ||
| height: options.height, | ||
| cfg_scale: options.cfgScale, | ||
| seed_resize_from_w: options.resizeSeedFromWidth, | ||
| seed_resize_from_h: options.resizeSeedFromHeight, | ||
| }; | ||
| if (options.hires) { | ||
| body = { | ||
| ...body, | ||
| enable_hr: true, | ||
| denoising_strength: options.hires.denoisingStrength, | ||
| hr_upscaler: options.hires.upscaler, | ||
| hr_scale: options.hires.upscaleBy, | ||
| hr_resize_x: options.hires.resizeWidthTo, | ||
| hr_resize_y: options.hires.resizeHeigthTo, | ||
| hr_second_pass_steps: options.hires.steps, | ||
| }; | ||
| } | ||
| const result = await (0, node_fetch_1.default)(`${apiUrl}/sdapi/v1/txt2img`, { | ||
| method: 'POST', | ||
| body: JSON.stringify(body), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| if (result.status !== 200) { | ||
| throw new Error(result.statusText); | ||
| } | ||
| const data = await result.json(); | ||
| if (!data?.images) { | ||
| throw new Error('api returned an invalid response'); | ||
| } | ||
| return data; | ||
| }; | ||
| exports.txt2img = txt2img; |
| import { txt2img } from './sdapi/txt2img.js'; | ||
| const sdwebui = (props) => { | ||
| const apiUrl = props?.apiUrl || 'http://localhost:7860'; | ||
| return { | ||
| apiUrl, | ||
| txt2img: (options) => txt2img(options, apiUrl), | ||
| }; | ||
| }; | ||
| export default sdwebui; |
| export * from './txt2img'; |
| import fetch from 'node-fetch'; | ||
| export const txt2img = async (options, apiUrl = 'http://localhost:7860') => { | ||
| let body = { | ||
| prompt: options.prompt, | ||
| negative_prompt: options.negativePrompt, | ||
| seed: options.seed, | ||
| subseed: options.variationSeed, | ||
| subseed_strength: options.variationSeedStrength, | ||
| sampler_name: options.samplingMethod, | ||
| batch_size: options.batchSize, | ||
| n_iter: options.batchCount, | ||
| steps: options.steps, | ||
| width: options.width, | ||
| height: options.height, | ||
| cfg_scale: options.cfgScale, | ||
| seed_resize_from_w: options.resizeSeedFromWidth, | ||
| seed_resize_from_h: options.resizeSeedFromHeight, | ||
| }; | ||
| if (options.hires) { | ||
| body = { | ||
| ...body, | ||
| enable_hr: true, | ||
| denoising_strength: options.hires.denoisingStrength, | ||
| hr_upscaler: options.hires.upscaler, | ||
| hr_scale: options.hires.upscaleBy, | ||
| hr_resize_x: options.hires.resizeWidthTo, | ||
| hr_resize_y: options.hires.resizeHeigthTo, | ||
| hr_second_pass_steps: options.hires.steps, | ||
| }; | ||
| } | ||
| const result = await fetch(`${apiUrl}/sdapi/v1/txt2img`, { | ||
| method: 'POST', | ||
| body: JSON.stringify(body), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| if (result.status !== 200) { | ||
| throw new Error(result.statusText); | ||
| } | ||
| const data = await result.json(); | ||
| if (!data?.images) { | ||
| throw new Error('api returned an invalid response'); | ||
| } | ||
| return data; | ||
| }; |
+20
| MIT License | ||
| Copyright (c) 2023 Brendan Goodenough | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the "Software"), to deal in | ||
| the Software without restriction, including without limitation the rights to | ||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| the Software, and to permit persons to whom the Software is furnished to do so, | ||
| subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
+76
| # Node Stable Diffusion WebUI Client | ||
| A Node.js client for using Automatic1111's Stable Diffusion WebUI. | ||
| ## Current Features | ||
| This project is a work in progress. The currently supported features are: | ||
| - txt2img generation | ||
| ## Installation | ||
| Add `node-sd-webui` to your project. | ||
| Using npm: | ||
| ```sh | ||
| npm i -S node-sd-webui | ||
| ``` | ||
| Using yarn: | ||
| ```sh | ||
| yarn add node-sd-webui | ||
| ``` | ||
| Using pnpm: | ||
| ```sh | ||
| pnpm add node-sd-webui | ||
| ``` | ||
| ## Usage | ||
| ### txt2img | ||
| The `txt2img` function allows you to generate an image using the `txt2img` | ||
| functionality of the Stable Diffusion WebUI. | ||
| Basic Example: | ||
| ```js | ||
| import sdwebui from 'node-sd-webui' | ||
| import { writeFileSync } from 'fs' | ||
| sdwebui() | ||
| .txt2img({ | ||
| prompt: 'A photo of a mushroom', | ||
| }) | ||
| .then(({ images }) => writeFileSync('path/to/image.png', images[0], 'base64')) | ||
| .catch((err) => console.error(err)) | ||
| ``` | ||
| Another example with a few more options: | ||
| ```js | ||
| import sdwebui from 'node-sd-webui' | ||
| import { writeFileSync } from 'fs' | ||
| sdwebui() | ||
| .txt2img({ | ||
| prompt: 'A photo of a mushroom, red cap, white spots', | ||
| negativePrompt: 'blurry, cartoon, drawing, illustration', | ||
| samplingMethod: 'DPM++ 2M Karras', | ||
| width: 768, | ||
| height: 512, | ||
| steps: 20, | ||
| batchSize: 5, | ||
| }) | ||
| .then(({ images }) => { | ||
| images.forEach((image, i) => | ||
| imagwriteFileSync(`path/to/image-${i}.png`, images[i], 'base64') | ||
| ) | ||
| }) | ||
| .catch((err) => console.error(err)) | ||
| ``` |
| import { Txt2ImgOptions, Txt2ImgResponse } from './sdapi/txt2img.js'; | ||
| type Props = { | ||
| apiUrl?: string; | ||
| }; | ||
| export type Client = { | ||
| apiUrl: string; | ||
| txt2img: (options: Txt2ImgOptions) => Promise<Txt2ImgResponse>; | ||
| }; | ||
| declare const sdwebui: (props?: Props) => Client; | ||
| export default sdwebui; |
| export * from './txt2img'; |
| export type Txt2ImgOptions = { | ||
| hires?: { | ||
| steps: number; | ||
| denoisingStrength: number; | ||
| upscaler: string; | ||
| upscaleBy?: number; | ||
| resizeWidthTo?: number; | ||
| resizeHeigthTo?: number; | ||
| }; | ||
| prompt: string; | ||
| negativePrompt?: string; | ||
| width?: number; | ||
| height?: number; | ||
| samplingMethod?: string; | ||
| seed?: number; | ||
| variationSeed?: number; | ||
| variationSeedStrength?: number; | ||
| resizeSeedFromHeight?: number; | ||
| resizeSeedFromWidth?: number; | ||
| batchSize?: number; | ||
| batchCount?: number; | ||
| steps?: number; | ||
| cfgScale?: number; | ||
| restoreFaces?: boolean; | ||
| }; | ||
| export type Txt2ImgResponse = { | ||
| images: string[]; | ||
| parameters: object; | ||
| info: string; | ||
| }; | ||
| export declare const txt2img: (options: Txt2ImgOptions, apiUrl?: string) => Promise<Txt2ImgResponse>; |
+9
-4
| { | ||
| "name": "node-sd-webui", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "type": "module", | ||
| "module": "./index.js", | ||
| "types": "./index.d.ts", | ||
| "license": "MIT", | ||
@@ -27,6 +25,13 @@ "dependencies": { | ||
| }, | ||
| "types": "types/index.d.ts", | ||
| "exports": { | ||
| "import": "./dist/esm/index.js", | ||
| "require": "./dist/cjs/index.js", | ||
| "default": "./dist/esm/index.js" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc && cp package.json ./dist/package.json", | ||
| "build:copy-files": "cp package.json ./dist/package.json && cp README.md ./dist/README.md && cp LICENSE ./dist/LICENSE", | ||
| "build": "tsc --project tsconfig.esm.json & tsc --project tsconfig.cjs.json && pnpm run build:copy-files", | ||
| "test": "ava" | ||
| } | ||
| } |
-10
| import { Txt2ImgOptions, Txt2ImgResponse } from './sdapi/txt2img.js'; | ||
| type Props = { | ||
| apiUrl?: string; | ||
| }; | ||
| export type Client = { | ||
| apiUrl: string; | ||
| txt2img: (options: Txt2ImgOptions) => Promise<Txt2ImgResponse>; | ||
| }; | ||
| declare const sdwebui: (props?: Props) => Client; | ||
| export default sdwebui; |
-9
| import { txt2img } from './sdapi/txt2img.js'; | ||
| const sdwebui = (props) => { | ||
| const apiUrl = props?.apiUrl || 'http://localhost:7860'; | ||
| return { | ||
| apiUrl, | ||
| txt2img: (options) => txt2img(options, apiUrl), | ||
| }; | ||
| }; | ||
| export default sdwebui; |
| export * from './txt2img'; |
| export * from './txt2img'; |
| export type Txt2ImgOptions = { | ||
| hires?: { | ||
| steps: number; | ||
| denoisingStrength: number; | ||
| upscaler: string; | ||
| upscaleBy?: number; | ||
| resizeWidthTo?: number; | ||
| resizeHeigthTo?: number; | ||
| }; | ||
| prompt: string; | ||
| negativePrompt?: string; | ||
| width?: number; | ||
| height?: number; | ||
| samplingMethod?: string; | ||
| seed?: number; | ||
| variationSeed?: number; | ||
| variationSeedStrength?: number; | ||
| resizeSeedFromHeight?: number; | ||
| resizeSeedFromWidth?: number; | ||
| batchSize?: number; | ||
| batchCount?: number; | ||
| steps?: number; | ||
| cfgScale?: number; | ||
| restoreFaces?: boolean; | ||
| }; | ||
| export type Txt2ImgResponse = { | ||
| images: string[]; | ||
| parameters: object; | ||
| info: string; | ||
| }; | ||
| export declare const txt2img: (options: Txt2ImgOptions, apiUrl?: string) => Promise<Txt2ImgResponse>; |
| import fetch from 'node-fetch'; | ||
| export const txt2img = async (options, apiUrl = 'http://localhost:7860') => { | ||
| let body = { | ||
| prompt: options.prompt, | ||
| negative_prompt: options.negativePrompt, | ||
| seed: options.seed, | ||
| subseed: options.variationSeed, | ||
| subseed_strength: options.variationSeedStrength, | ||
| sampler_name: options.samplingMethod, | ||
| batch_size: options.batchSize, | ||
| n_iter: options.batchCount, | ||
| steps: options.steps, | ||
| width: options.width, | ||
| height: options.height, | ||
| cfg_scale: options.cfgScale, | ||
| seed_resize_from_w: options.resizeSeedFromWidth, | ||
| seed_resize_from_h: options.resizeSeedFromHeight, | ||
| }; | ||
| if (options.hires) { | ||
| body = { | ||
| ...body, | ||
| enable_hr: true, | ||
| denoising_strength: options.hires.denoisingStrength, | ||
| hr_upscaler: options.hires.upscaler, | ||
| hr_scale: options.hires.upscaleBy, | ||
| hr_resize_x: options.hires.resizeWidthTo, | ||
| hr_resize_y: options.hires.resizeHeigthTo, | ||
| hr_second_pass_steps: options.hires.steps, | ||
| }; | ||
| } | ||
| const result = await fetch(`${apiUrl}/sdapi/v1/txt2img`, { | ||
| method: 'POST', | ||
| body: JSON.stringify(body), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| if (result.status !== 200) { | ||
| throw new Error(result.statusText); | ||
| } | ||
| const data = await result.json(); | ||
| if (!data?.images) { | ||
| throw new Error('api returned an invalid response'); | ||
| } | ||
| return data; | ||
| }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
9432
160.99%12
71.43%179
82.65%1
-50%77
Infinity%5
66.67%