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
node_modules
sdxl.gen.json

View File

@ -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": {

View File

@ -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('<config>', 'path to the config json')
.action(async (config) => {
.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();

View File

@ -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,
}),
});