From 4daac2c5b237ade31bfe634c8ece378756983402 Mon Sep 17 00:00:00 2001 From: hyper Date: Fri, 25 Oct 2024 13:48:42 +0800 Subject: [PATCH] fun with prodia... --- .gitignore | 1 + package.json | 3 +++ src/index.ts | 32 +++++++++++++++++++++++++------- src/prodia.ts | 4 ++-- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f1faa39..e574dad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ index.js node_modules +sdxl.gen.json diff --git a/package.json b/package.json index b78a264..8b9bd19 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "test": "echo \"Error: no test specified\" && exit 1", "build": "esbuild src/index.ts --bundle --outfile=index.js --platform=node" }, + "bin":{ + "prodia": "./index.js" + }, "author": "", "license": "ISC", "devDependencies": { diff --git a/src/index.ts b/src/index.ts index 30af28f..b6c8a2a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ +#!node import { program } from 'commander'; import * as fs from 'fs/promises'; -import { fetchProdia } from './prodia'; +import { defaultProdiaParams, fetchProdia } from './prodia'; program .name('prodia-scripts') @@ -10,10 +11,27 @@ program program .command('sdxl') .description('generate an image with sdxl') - .argument('', 'path to the config json') - .action(async (config) => { - const txt = await fs.readFile(config, { encoding: 'utf8' }); - const json = JSON.parse(txt); - const status = await fetchProdia(json); - console.log('done:', status); + .argument('[config]', 'path to the config json', './sdxl.gen.json') + .option('--init', 'create a default sdxl.gen.json') + .action(async (config, flags) => { + console.log(config, flags); + + if (flags.init) { + console.log('Creating sdxl.gen.json...'); + await fs.writeFile( + './sdxl.gen.json', + JSON.stringify(defaultProdiaParams, null, 4) + ); + return; + } else { + console.log(`Reading config=${config}...`); + const txt = await fs.readFile(config, { encoding: 'utf8' }); + const json = JSON.parse(txt); + + console.log(`Fetching prodia api...`); + const status = await fetchProdia(json); + console.log('done:', status); + } }); + +program.parse(); diff --git a/src/prodia.ts b/src/prodia.ts index 1a46fe1..c342c79 100644 --- a/src/prodia.ts +++ b/src/prodia.ts @@ -19,7 +19,7 @@ type ProdiaResponse = { imageUrl?: string; }; -const defaultParams: ProdiaParams = { +export const defaultProdiaParams: ProdiaParams = { model: 'sd_xl_base_1.0.safetensors [be9edd61]', prompt: 'puppies in a cloud', negative_prompt: 'badly drawn', @@ -44,7 +44,7 @@ export async function fetchProdia( 'X-Prodia-Key': '6e169a7f-444f-4c22-8353-b9a77d42645c', }, body: JSON.stringify({ - ...defaultParams, + ...defaultProdiaParams, ...params, }), });