mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
* Implements rudimentary api * Fixes blocking in API * Adds UI to monorepo > src/frontend/ * Updates frontend/README * Reverts conda env name to `ldm` * Fixes environment yamls * CORS config for testing * Fixes LogViewer position * API WID * Adds actions to image viewer * Increases vite chunkSizeWarningLimit to 1500 * Implements init image * Implements state persistence in localStorage * Improve progress data handling * Final build * Fixes mimetypes error on windows * Adds error logging * Fixes bugged img2img strength component * Adds sourcemaps to dev build * Fixes missing key * Changes connection status indicator to text * Adds ability to serve other hosts than localhost * Adding Flask API server * Removes source maps from config * Fixes prop transfer * Add missing packages and add CORS support * Adding API doc * Remove defaults from openapi doc * Adds basic error handling for server config query * Mostly working socket.io implementation. * Fixes bug preventing mask upload * Fixes bug with sampler name not written to metadata * UI Overhaul, numerous fixes Co-authored-by: Kyle Schouviller <kyle0654@hotmail.com> Co-authored-by: Lincoln Stein <lincoln.stein@gmail.com>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
export interface SeedWeightPair {
|
|
seed: number;
|
|
weight: number;
|
|
}
|
|
|
|
export type SeedWeights = Array<Array<number>>;
|
|
|
|
export const stringToSeedWeights = (string: string): SeedWeights | boolean => {
|
|
const stringPairs = string.split(',');
|
|
const arrPairs = stringPairs.map((p) => p.split(':'));
|
|
const pairs = arrPairs.map((p) => {
|
|
return [parseInt(p[0]), parseFloat(p[1])];
|
|
});
|
|
|
|
if (!validateSeedWeights(pairs)) {
|
|
return false;
|
|
}
|
|
|
|
return pairs;
|
|
};
|
|
|
|
export const validateSeedWeights = (
|
|
seedWeights: SeedWeights | string
|
|
): boolean => {
|
|
return typeof seedWeights === 'string'
|
|
? Boolean(stringToSeedWeights(seedWeights))
|
|
: Boolean(
|
|
seedWeights.length &&
|
|
!seedWeights.some((pair) => {
|
|
const [seed, weight] = pair;
|
|
const isSeedValid = !isNaN(parseInt(seed.toString(), 10));
|
|
const isWeightValid =
|
|
!isNaN(parseInt(weight.toString(), 10)) &&
|
|
weight >= 0 &&
|
|
weight <= 1;
|
|
return !(isSeedValid && isWeightValid);
|
|
})
|
|
);
|
|
};
|
|
|
|
export const seedWeightsToString = (
|
|
seedWeights: SeedWeights
|
|
): string | boolean => {
|
|
if (!validateSeedWeights(seedWeights)) {
|
|
return false;
|
|
}
|
|
|
|
return seedWeights.reduce((acc, pair, i, arr) => {
|
|
const [seed, weight] = pair;
|
|
acc += `${seed}:${weight}`;
|
|
if (i !== arr.length - 1) {
|
|
acc += ',';
|
|
}
|
|
return acc;
|
|
}, '');
|
|
};
|