fun with prodia...

This commit is contained in:
hyper 2024-10-25 13:48:42 +08:00
parent 7d7cab9971
commit 4daac2c5b2
4 changed files with 31 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
index.js index.js
node_modules node_modules
sdxl.gen.json

View File

@ -7,6 +7,9 @@
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "esbuild src/index.ts --bundle --outfile=index.js --platform=node" "build": "esbuild src/index.ts --bundle --outfile=index.js --platform=node"
}, },
"bin":{
"prodia": "./index.js"
},
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {

View File

@ -1,6 +1,7 @@
#!node
import { program } from 'commander'; import { program } from 'commander';
import * as fs from 'fs/promises'; import * as fs from 'fs/promises';
import { fetchProdia } from './prodia'; import { defaultProdiaParams, fetchProdia } from './prodia';
program program
.name('prodia-scripts') .name('prodia-scripts')
@ -10,10 +11,27 @@ program
program program
.command('sdxl') .command('sdxl')
.description('generate an image with sdxl') .description('generate an image with sdxl')
.argument('<config>', 'path to the config json') .argument('[config]', 'path to the config json', './sdxl.gen.json')
.action(async (config) => { .option('--init', 'create a default sdxl.gen.json')
const txt = await fs.readFile(config, { encoding: 'utf8' }); .action(async (config, flags) => {
const json = JSON.parse(txt); console.log(config, flags);
const status = await fetchProdia(json);
console.log('done:', status); 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();

View File

@ -19,7 +19,7 @@ type ProdiaResponse = {
imageUrl?: string; imageUrl?: string;
}; };
const defaultParams: ProdiaParams = { export const defaultProdiaParams: ProdiaParams = {
model: 'sd_xl_base_1.0.safetensors [be9edd61]', model: 'sd_xl_base_1.0.safetensors [be9edd61]',
prompt: 'puppies in a cloud', prompt: 'puppies in a cloud',
negative_prompt: 'badly drawn', negative_prompt: 'badly drawn',
@ -44,7 +44,7 @@ export async function fetchProdia(
'X-Prodia-Key': '6e169a7f-444f-4c22-8353-b9a77d42645c', 'X-Prodia-Key': '6e169a7f-444f-4c22-8353-b9a77d42645c',
}, },
body: JSON.stringify({ body: JSON.stringify({
...defaultParams, ...defaultProdiaParams,
...params, ...params,
}), }),
}); });