default append & prodia transform

This commit is contained in:
hyper 2024-10-25 16:04:17 +08:00
parent ed13a48f12
commit 4197f66402
3 changed files with 20 additions and 6 deletions

2
.gitignore vendored
View File

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

View File

@ -13,7 +13,7 @@ program
.description('generate an image with sdxl')
.argument('[config]', 'path to the config json', './sdxl.gen.json')
.option('--init', 'create a default sdxl.gen.json')
.option('--append [where]', 'saves generated url to a text file')
.option('--append [where]', 'saves generated url to a text file', './generated.txt')
.option('--queue [amount]', 'queues jobs without waiting for them')
.action(async (config, flags) => {
if (flags.init) {
@ -37,11 +37,10 @@ program
for (let i = 0; i < queue; i++) {
console.log(`Fetching ${i + 1}/${queue}...`);
const job = await fetchProdia(json);
const url = `https://images.prodia.xyz/${job.job}.png`;
if (flags.append)
await fs.appendFile(
flags.append,
`https://images.prodia.xyz/${job.job}.png\n`
);
await fs.appendFile(flags.append, url + '\n');
console.log(url);
}
console.log('Done!');
} else {

View File

@ -1,4 +1,5 @@
import fetch from 'node-fetch';
import * as fs from 'fs/promises';
type ProdiaParams = {
model: string;
@ -11,6 +12,12 @@ type ProdiaParams = {
sampler: string;
width: number;
height: number;
// transform params
denoising_strength: number;
upscale: boolean;
inputImage?: string;
imageData?: string;
};
type ProdiaResponse = {
@ -30,12 +37,20 @@ export const defaultProdiaParams: ProdiaParams = {
sampler: 'DPM++ 2M Karras',
width: 1024,
height: 1024,
denoising_strength: 0.7,
upscale: false,
};
export async function fetchProdia(
params: Partial<ProdiaParams>,
endpoint = 'sdxl/generate'
) {
if(params.inputImage){
const data = await fs.readFile(params.inputImage);
params.imageData = data.toString('base64');
delete params.inputImage;
}
const resp = await fetch(`https://api.prodia.com/v1/${endpoint}`, {
method: 'POST',
headers: {