node-sd-webui
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.img2img = void 0; | ||
| const img2img = async (options, apiUrl = 'http://localhost:7860') => { | ||
| let body = { | ||
| init_images: options.imageData, | ||
| 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, | ||
| }; | ||
| /* @ts-ignore */ | ||
| const result = await fetch(`${apiUrl}/sdapi/v1/img2img`, { | ||
| 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.img2img = img2img; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.pngInfo = void 0; | ||
| const pngInfo = async (options, apiUrl = 'http://localhost:7860') => { | ||
| const body = { | ||
| image: options.imageData, | ||
| }; | ||
| /* @ts-ignore */ | ||
| const result = await fetch(`${apiUrl}/sdapi/v1/png-info`, { | ||
| 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?.info) { | ||
| throw new Error('api returned an invalid response'); | ||
| } | ||
| const split = data.info.split('\n'); | ||
| let offset = 0; | ||
| let negativePrompt; | ||
| if (split[1].startsWith('Negative prompt:')) { | ||
| negativePrompt = split[1].slice(split[1].indexOf(':') + 1).trim(); | ||
| offset++; | ||
| } | ||
| const values = split[offset + 1] | ||
| .split(',') | ||
| .map((val) => val.split(': ')[1]); | ||
| const size = values[4].split('x'); | ||
| const response = { | ||
| prompt: split[0], | ||
| steps: Number.parseInt(values[0]), | ||
| samplingMethod: values[1], | ||
| cfgScale: Number.parseInt(values[2]), | ||
| seed: Number.parseInt(values[3]), | ||
| width: Number.parseInt(size[0]), | ||
| height: Number.parseInt(size[1]), | ||
| modelHash: values[5], | ||
| model: values[6], | ||
| }; | ||
| if (negativePrompt) { | ||
| response.negativePrompt = negativePrompt; | ||
| } | ||
| return response; | ||
| }; | ||
| exports.pngInfo = pngInfo; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.SamplingMethod = void 0; | ||
| var SamplingMethod; | ||
| (function (SamplingMethod) { | ||
| SamplingMethod["Euler_A"] = "Euler a"; | ||
| SamplingMethod["Euler"] = "Euler"; | ||
| SamplingMethod["LMS"] = "LMS"; | ||
| SamplingMethod["Heun"] = "Heun"; | ||
| SamplingMethod["DPM2"] = "DPM2"; | ||
| SamplingMethod["DPM2_A"] = "DPM2 a"; | ||
| SamplingMethod["DPMPlusPlus_S2_A"] = "DPM++ S2 a"; | ||
| SamplingMethod["DPMPlusPlus_2M"] = "DPM++ 2M"; | ||
| SamplingMethod["DPMPlusPlus_SDE"] = "DPM++ SDE"; | ||
| SamplingMethod["DPM_Fast"] = "DPM fast"; | ||
| SamplingMethod["DPM_Adaptive"] = "DPM adaptive"; | ||
| SamplingMethod["LMS_Karras"] = "LMS Karras"; | ||
| SamplingMethod["DPM2_Karras"] = "DPM2 Karras"; | ||
| SamplingMethod["DPM2_A_Karras"] = "DPM2 a Karras"; | ||
| SamplingMethod["DPMPlusPlus_2S_A_Karras"] = "DPM++ 2S a Karras"; | ||
| SamplingMethod["DPMPlusPlus_2M_Karras"] = "DPM++ 2M Karras"; | ||
| SamplingMethod["DPMPlusPlus_SDE_Karras"] = "DPM++ SDE Karras"; | ||
| SamplingMethod["DDIM"] = "DDIM"; | ||
| SamplingMethod["PLMS"] = "PLMS"; | ||
| })(SamplingMethod = exports.SamplingMethod || (exports.SamplingMethod = {})); |
| export const img2img = async (options, apiUrl = 'http://localhost:7860') => { | ||
| let body = { | ||
| init_images: options.imageData, | ||
| 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, | ||
| }; | ||
| /* @ts-ignore */ | ||
| const result = await fetch(`${apiUrl}/sdapi/v1/img2img`, { | ||
| 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; | ||
| }; |
| export const pngInfo = async (options, apiUrl = 'http://localhost:7860') => { | ||
| const body = { | ||
| image: options.imageData, | ||
| }; | ||
| /* @ts-ignore */ | ||
| const result = await fetch(`${apiUrl}/sdapi/v1/png-info`, { | ||
| 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?.info) { | ||
| throw new Error('api returned an invalid response'); | ||
| } | ||
| const split = data.info.split('\n'); | ||
| let offset = 0; | ||
| let negativePrompt; | ||
| if (split[1].startsWith('Negative prompt:')) { | ||
| negativePrompt = split[1].slice(split[1].indexOf(':') + 1).trim(); | ||
| offset++; | ||
| } | ||
| const values = split[offset + 1] | ||
| .split(',') | ||
| .map((val) => val.split(': ')[1]); | ||
| const size = values[4].split('x'); | ||
| const response = { | ||
| prompt: split[0], | ||
| steps: Number.parseInt(values[0]), | ||
| samplingMethod: values[1], | ||
| cfgScale: Number.parseInt(values[2]), | ||
| seed: Number.parseInt(values[3]), | ||
| width: Number.parseInt(size[0]), | ||
| height: Number.parseInt(size[1]), | ||
| modelHash: values[5], | ||
| model: values[6], | ||
| }; | ||
| if (negativePrompt) { | ||
| response.negativePrompt = negativePrompt; | ||
| } | ||
| return response; | ||
| }; |
| export var SamplingMethod; | ||
| (function (SamplingMethod) { | ||
| SamplingMethod["Euler_A"] = "Euler a"; | ||
| SamplingMethod["Euler"] = "Euler"; | ||
| SamplingMethod["LMS"] = "LMS"; | ||
| SamplingMethod["Heun"] = "Heun"; | ||
| SamplingMethod["DPM2"] = "DPM2"; | ||
| SamplingMethod["DPM2_A"] = "DPM2 a"; | ||
| SamplingMethod["DPMPlusPlus_S2_A"] = "DPM++ S2 a"; | ||
| SamplingMethod["DPMPlusPlus_2M"] = "DPM++ 2M"; | ||
| SamplingMethod["DPMPlusPlus_SDE"] = "DPM++ SDE"; | ||
| SamplingMethod["DPM_Fast"] = "DPM fast"; | ||
| SamplingMethod["DPM_Adaptive"] = "DPM adaptive"; | ||
| SamplingMethod["LMS_Karras"] = "LMS Karras"; | ||
| SamplingMethod["DPM2_Karras"] = "DPM2 Karras"; | ||
| SamplingMethod["DPM2_A_Karras"] = "DPM2 a Karras"; | ||
| SamplingMethod["DPMPlusPlus_2S_A_Karras"] = "DPM++ 2S a Karras"; | ||
| SamplingMethod["DPMPlusPlus_2M_Karras"] = "DPM++ 2M Karras"; | ||
| SamplingMethod["DPMPlusPlus_SDE_Karras"] = "DPM++ SDE Karras"; | ||
| SamplingMethod["DDIM"] = "DDIM"; | ||
| SamplingMethod["PLMS"] = "PLMS"; | ||
| })(SamplingMethod || (SamplingMethod = {})); |
| export type Img2ImgOptions = { | ||
| imageData: string[]; | ||
| 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 Img2ImgResponse = { | ||
| images: string[]; | ||
| parameters: object; | ||
| info: string; | ||
| }; | ||
| export declare const img2img: (options: Img2ImgOptions, apiUrl?: string) => Promise<Img2ImgResponse>; |
| export type PngInfoOptions = { | ||
| imageData: string; | ||
| }; | ||
| export type PngInfoResponse = { | ||
| prompt: string; | ||
| negativePrompt?: string; | ||
| steps: number; | ||
| samplingMethod: string; | ||
| cfgScale: number; | ||
| seed: number; | ||
| width: number; | ||
| height: number; | ||
| modelHash: string; | ||
| model: string; | ||
| }; | ||
| export declare const pngInfo: (options: PngInfoOptions, apiUrl?: string) => Promise<PngInfoResponse>; |
| export declare enum SamplingMethod { | ||
| Euler_A = "Euler a", | ||
| Euler = "Euler", | ||
| LMS = "LMS", | ||
| Heun = "Heun", | ||
| DPM2 = "DPM2", | ||
| DPM2_A = "DPM2 a", | ||
| DPMPlusPlus_S2_A = "DPM++ S2 a", | ||
| DPMPlusPlus_2M = "DPM++ 2M", | ||
| DPMPlusPlus_SDE = "DPM++ SDE", | ||
| DPM_Fast = "DPM fast", | ||
| DPM_Adaptive = "DPM adaptive", | ||
| LMS_Karras = "LMS Karras", | ||
| DPM2_Karras = "DPM2 Karras", | ||
| DPM2_A_Karras = "DPM2 a Karras", | ||
| DPMPlusPlus_2S_A_Karras = "DPM++ 2S a Karras", | ||
| DPMPlusPlus_2M_Karras = "DPM++ 2M Karras", | ||
| DPMPlusPlus_SDE_Karras = "DPM++ SDE Karras", | ||
| DDIM = "DDIM", | ||
| PLMS = "PLMS" | ||
| } |
+19
-0
| "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 }); | ||
| const img2img_js_1 = require("./sdapi/img2img.js"); | ||
| const pngInfo_js_1 = require("./sdapi/pngInfo.js"); | ||
| const txt2img_js_1 = require("./sdapi/txt2img.js"); | ||
| __exportStar(require("./sdapi/types.js"), exports); | ||
| const sdwebui = (props) => { | ||
@@ -8,2 +25,4 @@ const apiUrl = props?.apiUrl || 'http://localhost:7860'; | ||
| apiUrl, | ||
| pngInfo: (options) => (0, pngInfo_js_1.pngInfo)(options, apiUrl), | ||
| img2img: (options) => (0, img2img_js_1.img2img)(options, apiUrl), | ||
| txt2img: (options) => (0, txt2img_js_1.txt2img)(options, apiUrl), | ||
@@ -10,0 +29,0 @@ }; |
@@ -18,1 +18,4 @@ "use strict"; | ||
| __exportStar(require("./txt2img"), exports); | ||
| __exportStar(require("./img2img"), exports); | ||
| __exportStar(require("./pngInfo"), exports); | ||
| __exportStar(require("./types"), exports); |
@@ -33,2 +33,9 @@ "use strict"; | ||
| } | ||
| if (options.script) { | ||
| body = { | ||
| ...body, | ||
| script_name: options.script.name, | ||
| script_args: options.script.args || [], | ||
| }; | ||
| } | ||
| /* @ts-ignore */ | ||
@@ -35,0 +42,0 @@ const result = await fetch(`${apiUrl}/sdapi/v1/txt2img`, { |
+5
-0
@@ -0,2 +1,5 @@ | ||
| import { img2img } from './sdapi/img2img.js'; | ||
| import { pngInfo } from './sdapi/pngInfo.js'; | ||
| import { txt2img } from './sdapi/txt2img.js'; | ||
| export * from './sdapi/types.js'; | ||
| const sdwebui = (props) => { | ||
@@ -6,2 +9,4 @@ const apiUrl = props?.apiUrl || 'http://localhost:7860'; | ||
| apiUrl, | ||
| pngInfo: (options) => pngInfo(options, apiUrl), | ||
| img2img: (options) => img2img(options, apiUrl), | ||
| txt2img: (options) => txt2img(options, apiUrl), | ||
@@ -8,0 +13,0 @@ }; |
| export * from './txt2img'; | ||
| export * from './img2img'; | ||
| export * from './pngInfo'; | ||
| export * from './types'; |
@@ -30,2 +30,9 @@ export const txt2img = async (options, apiUrl = 'http://localhost:7860') => { | ||
| } | ||
| if (options.script) { | ||
| body = { | ||
| ...body, | ||
| script_name: options.script.name, | ||
| script_args: options.script.args || [], | ||
| }; | ||
| } | ||
| /* @ts-ignore */ | ||
@@ -32,0 +39,0 @@ const result = await fetch(`${apiUrl}/sdapi/v1/txt2img`, { |
+1
-1
| { | ||
| "name": "node-sd-webui", | ||
| "version": "0.0.5", | ||
| "version": "0.0.6", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "engines": { |
+5
-3
@@ -9,3 +9,5 @@ # Node Stable Diffusion WebUI Client | ||
| - txt2img generation | ||
| - [x] txt2img generation | ||
| - [x] img2img generation | ||
| - [x] pngInfo support | ||
@@ -58,3 +60,3 @@ ## Installation | ||
| ```js | ||
| import sdwebui from 'node-sd-webui' | ||
| import sdwebui, { SamplingMethod } from 'node-sd-webui' | ||
| import { writeFileSync } from 'fs' | ||
@@ -66,3 +68,3 @@ | ||
| negativePrompt: 'blurry, cartoon, drawing, illustration', | ||
| samplingMethod: 'DPM++ 2M Karras', | ||
| samplingMethod: SamplingMethod.Euler_A, | ||
| width: 768, | ||
@@ -69,0 +71,0 @@ height: 512, |
+5
-0
@@ -0,2 +1,5 @@ | ||
| import { Img2ImgOptions, Img2ImgResponse } from './sdapi/img2img.js'; | ||
| import { PngInfoOptions, PngInfoResponse } from './sdapi/pngInfo.js'; | ||
| import { Txt2ImgOptions, Txt2ImgResponse } from './sdapi/txt2img.js'; | ||
| export * from './sdapi/types.js'; | ||
| type Props = { | ||
@@ -7,2 +10,4 @@ apiUrl?: string; | ||
| apiUrl: string; | ||
| pngInfo: (options: PngInfoOptions) => Promise<PngInfoResponse>; | ||
| img2img: (options: Img2ImgOptions) => Promise<Img2ImgResponse>; | ||
| txt2img: (options: Txt2ImgOptions) => Promise<Txt2ImgResponse>; | ||
@@ -9,0 +14,0 @@ }; |
| export * from './txt2img'; | ||
| export * from './img2img'; | ||
| export * from './pngInfo'; | ||
| export * from './types'; |
@@ -25,2 +25,6 @@ export type Txt2ImgOptions = { | ||
| restoreFaces?: boolean; | ||
| script?: { | ||
| name: string; | ||
| args?: string[]; | ||
| }; | ||
| }; | ||
@@ -27,0 +31,0 @@ export type Txt2ImgResponse = { |
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
20207
135.29%21
75%510
189.77%79
2.6%6
200%