1
0
Fork 0

clean up chain params to match backend

This commit is contained in:
Sean Sube 2023-09-13 17:28:38 -05:00
parent a33c88e670
commit c9f7caae39
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
36 changed files with 498 additions and 484 deletions

View File

@ -9,7 +9,7 @@
"name": "save-local",
"type": "persist-disk",
"params": {
"tile_size": "hd8k"
"tiles": "hd8k"
}
}
]

View File

@ -23,14 +23,14 @@
"prompt": "a magical wizard in a robe fighting a dragon",
"scale": 4,
"outscale": 4,
"tile_size": "mini"
"tiles": "mini"
}
},
{
"name": "save-local",
"type": "persist-disk",
"params": {
"tile_size": "hd8k"
"tiles": "hd8k"
}
},
{
@ -40,7 +40,7 @@
"bucket": "storage-stable-diffusion",
"endpoint_url": "http://scylla.home.holdmyran.ch:8000",
"profile_name": "ceph",
"tile_size": "hd8k"
"tiles": "hd8k"
}
}
]

View File

@ -20,7 +20,7 @@
"name": "save-local",
"type": "persist-disk",
"params": {
"tile_size": "hd8k"
"tiles": "hd8k"
}
}
]

View File

@ -66,7 +66,7 @@ and can also save intermediate output, such as the result of a `source-txt2img`
"name": "save-local",
"type": "persist-disk",
"params": {
"tile_size": "hd8k"
"tiles": "hd8k"
}
}
]

View File

@ -2,29 +2,31 @@
import { doesExist, InvalidArgumentError, Maybe } from '@apextoaster/js-utils';
import { ServerParams } from '../config.js';
import { range } from '../utils.js';
import {
ApiClient,
BaseImgParams,
BlendParams,
ChainPipeline,
FilterResponse,
HighresParams,
ImageResponse,
ImageResponseWithRetry,
ModelResponse,
ReadyResponse,
RetryParams,
WriteExtrasResponse,
} from '../types/api.js';
import { ChainPipeline } from '../types/chain.js';
import { ExtrasFile } from '../types/model.js';
import {
BaseImgParams,
BlendParams,
HighresParams,
Img2ImgParams,
InpaintParams,
ModelParams,
ModelResponse,
OutpaintParams,
ReadyResponse,
RetryParams,
Txt2ImgParams,
UpscaleParams,
UpscaleReqParams,
WriteExtrasResponse,
} from './types.js';
import { ExtrasFile } from '../types.js';
} from '../types/params.js';
import { range } from '../utils.js';
import { ApiClient } from './base.js';
/**
* Fixed precision for integer parameters.

110
gui/src/client/base.ts Normal file
View File

@ -0,0 +1,110 @@
import { ServerParams } from '../config.js';
import { ExtrasFile } from '../types/model.js';
import { WriteExtrasResponse, FilterResponse, ModelResponse, ImageResponseWithRetry, ImageResponse, ReadyResponse, RetryParams } from '../types/api.js';
import { ChainPipeline } from '../types/chain.js';
import { ModelParams, Txt2ImgParams, UpscaleParams, HighresParams, Img2ImgParams, InpaintParams, OutpaintParams, UpscaleReqParams, BlendParams } from '../types/params.js';
export interface ApiClient {
extras(): Promise<ExtrasFile>;
writeExtras(extras: ExtrasFile): Promise<WriteExtrasResponse>;
/**
* List the available filter masks for inpaint.
*/
filters(): Promise<FilterResponse>;
/**
* List the available models.
*/
models(): Promise<ModelResponse>;
/**
* List the available noise sources for inpaint.
*/
noises(): Promise<Array<string>>;
/**
* Get the valid server parameters to validate image parameters.
*/
params(): Promise<ServerParams>;
/**
* Get the available pipelines.
*/
pipelines(): Promise<Array<string>>;
/**
* Get the available hardware acceleration platforms.
*/
platforms(): Promise<Array<string>>;
/**
* List the available pipeline schedulers.
*/
schedulers(): Promise<Array<string>>;
/**
* Load extra strings from the server.
*/
strings(): Promise<Record<string, {
translation: Record<string, string>;
}>>;
/**
* Start a txt2img pipeline.
*/
txt2img(model: ModelParams, params: Txt2ImgParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start an im2img pipeline.
*/
img2img(model: ModelParams, params: Img2ImgParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start an inpaint pipeline.
*/
inpaint(model: ModelParams, params: InpaintParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start an outpaint pipeline.
*/
outpaint(model: ModelParams, params: OutpaintParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start an upscale pipeline.
*/
upscale(model: ModelParams, params: UpscaleReqParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start a blending pipeline.
*/
blend(model: ModelParams, params: BlendParams, upscale?: UpscaleParams): Promise<ImageResponseWithRetry>;
chain(model: ModelParams, chain: ChainPipeline): Promise<ImageResponse>;
/**
* Check whether job has finished and its output is ready.
*/
ready(key: string): Promise<ReadyResponse>;
/**
* Cancel an existing job.
*/
cancel(key: string): Promise<boolean>;
/**
* Retry a previous job using the same parameters.
*/
retry(params: RetryParams): Promise<ImageResponseWithRetry>;
/**
* Restart the image job workers.
*/
restart(): Promise<boolean>;
/**
* Check the status of the image job workers.
*/
status(): Promise<Array<unknown>>;
}

View File

@ -1,6 +1,6 @@
import { BaseError } from 'noicejs';
import { ApiClient } from './types.js';
import { ApiClient } from './base.js';
export class NoServerError extends BaseError {
constructor() {

View File

@ -1,425 +0,0 @@
import { ServerParams } from '../config.js';
import { ExtrasFile } from '../types.js';
/**
* Shared parameters for anything using models, which is pretty much everything.
*/
export interface ModelParams {
/**
* The diffusion model to use.
*/
model: string;
/**
* Specialized pipeline to use.
*/
pipeline: string;
/**
* The hardware acceleration platform to use.
*/
platform: string;
/**
* The upscaling model to use.
*/
upscaling: string;
/**
* The correction model to use.
*/
correction: string;
/**
* ControlNet to be used.
*/
control: string;
}
/**
* Shared parameters for most of the image requests.
*/
export interface BaseImgParams {
scheduler: string;
prompt: string;
negativePrompt?: string;
batch: number;
tiledVAE: boolean;
tiles: number;
overlap: number;
stride: number;
cfg: number;
steps: number;
seed: number;
eta: number;
}
/**
* Parameters for txt2img requests.
*/
export interface Txt2ImgParams extends BaseImgParams {
width: number;
height: number;
}
/**
* Parameters for img2img requests.
*/
export interface Img2ImgParams extends BaseImgParams {
source: Blob;
loopback: number;
sourceFilter: string;
strength: number;
}
/**
* Parameters for inpaint requests.
*/
export interface InpaintParams extends BaseImgParams {
mask: Blob;
source: Blob;
filter: string;
noise: string;
strength: number;
fillColor: string;
tileOrder: string;
}
/**
* Additional parameters for outpaint border.
*
* @todo should be nested under inpaint/outpaint params
*/
export interface OutpaintPixels {
enabled: boolean;
left: number;
right: number;
top: number;
bottom: number;
}
/**
* Parameters for outpaint requests.
*/
export type OutpaintParams = InpaintParams & OutpaintPixels;
/**
* Additional parameters for the inpaint brush.
*
* These are not currently sent to the server and only stored in state.
*
* @todo move to state
*/
export interface BrushParams {
color: number;
size: number;
strength: number;
}
/**
* Additional parameters for upscaling. May be sent with most other requests to run a post-pipeline.
*/
export interface UpscaleParams {
enabled: boolean;
upscaleOrder: string;
denoise: number;
scale: number;
outscale: number;
faces: boolean;
faceStrength: number;
faceOutscale: number;
}
/**
* Parameters for upscale requests.
*/
export interface UpscaleReqParams extends BaseImgParams {
source: Blob;
}
/**
* Parameters for blend requests.
*/
export interface BlendParams {
sources: Array<Blob>;
mask: Blob;
}
export interface HighresParams {
enabled: boolean;
highresIterations: number;
highresMethod: string;
highresScale: number;
highresSteps: number;
highresStrength: number;
}
export interface ChainStageParams {
tile_size: number;
}
export interface Txt2ImgStage {
name: string;
type: 'source-txt2img';
params: Partial<Txt2ImgParams & ChainStageParams>;
}
export interface Img2ImgStage {
name: string;
type: 'blend-img2img';
params: Partial<Img2ImgParams & ChainStageParams>;
}
export interface GridStage {
name: string;
type: 'blend-grid';
params: Partial<{
height: number;
width: number;
} & ChainStageParams>;
}
export interface OutputStage {
name: string;
type: 'persist-disk';
params: Partial<ChainStageParams>;
}
export interface ChainPipeline {
/* defaults?: {
txt2img?: Txt2ImgParams;
img2img?: Img2ImgParams;
}; */
defaults?: Txt2ImgParams & ModelParams;
stages: Array<Txt2ImgStage | Img2ImgStage | GridStage | OutputStage>;
}
/**
* Output image data within the response.
*/
export interface ImageOutput {
key: string;
url: string;
}
/**
* Output image size, after upscaling and outscale.
*/
export interface ImageSize {
width: number;
height: number;
}
/**
* General response for most image requests.
*/
export interface ImageResponse {
outputs: Array<ImageOutput>;
params: Required<BaseImgParams> & Required<ModelParams>;
size: ImageSize;
}
/**
* Status response from the ready endpoint.
*/
export interface ReadyResponse {
cancelled: boolean;
failed: boolean;
progress: number;
ready: boolean;
}
export interface NetworkModel {
name: string;
type: 'control' | 'inversion' | 'lora';
// TODO: add token
// TODO: add layer/token count
}
export interface FilterResponse {
mask: Array<string>;
source: Array<string>;
}
/**
* List of available models.
*/
export interface ModelResponse {
correction: Array<string>;
diffusion: Array<string>;
networks: Array<NetworkModel>;
upscaling: Array<string>;
}
export interface WriteExtrasResponse {
file: string;
successful: Array<string>;
errors: Array<string>;
}
export type RetryParams = {
type: 'txt2img';
model: ModelParams;
params: Txt2ImgParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'img2img';
model: ModelParams;
params: Img2ImgParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'inpaint';
model: ModelParams;
params: InpaintParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'outpaint';
model: ModelParams;
params: OutpaintParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'upscale';
model: ModelParams;
params: UpscaleReqParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'blend';
model: ModelParams;
params: BlendParams;
upscale?: UpscaleParams;
};
export interface ImageResponseWithRetry {
image: ImageResponse;
retry: RetryParams;
}
export interface ImageMetadata {
highres: HighresParams;
outputs: string | Array<string>;
params: Txt2ImgParams | Img2ImgParams | InpaintParams;
upscale: UpscaleParams;
input_size: ImageSize;
size: ImageSize;
}
export interface ApiClient {
extras(): Promise<ExtrasFile>;
writeExtras(extras: ExtrasFile): Promise<WriteExtrasResponse>;
/**
* List the available filter masks for inpaint.
*/
filters(): Promise<FilterResponse>;
/**
* List the available models.
*/
models(): Promise<ModelResponse>;
/**
* List the available noise sources for inpaint.
*/
noises(): Promise<Array<string>>;
/**
* Get the valid server parameters to validate image parameters.
*/
params(): Promise<ServerParams>;
/**
* Get the available pipelines.
*/
pipelines(): Promise<Array<string>>;
/**
* Get the available hardware acceleration platforms.
*/
platforms(): Promise<Array<string>>;
/**
* List the available pipeline schedulers.
*/
schedulers(): Promise<Array<string>>;
/**
* Load extra strings from the server.
*/
strings(): Promise<Record<string, {
translation: Record<string, string>;
}>>;
/**
* Start a txt2img pipeline.
*/
txt2img(model: ModelParams, params: Txt2ImgParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start an im2img pipeline.
*/
img2img(model: ModelParams, params: Img2ImgParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start an inpaint pipeline.
*/
inpaint(model: ModelParams, params: InpaintParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start an outpaint pipeline.
*/
outpaint(model: ModelParams, params: OutpaintParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start an upscale pipeline.
*/
upscale(model: ModelParams, params: UpscaleReqParams, upscale?: UpscaleParams, highres?: HighresParams): Promise<ImageResponseWithRetry>;
/**
* Start a blending pipeline.
*/
blend(model: ModelParams, params: BlendParams, upscale?: UpscaleParams): Promise<ImageResponseWithRetry>;
chain(model: ModelParams, chain: ChainPipeline): Promise<ImageResponse>;
/**
* Check whether job has finished and its output is ready.
*/
ready(key: string): Promise<ReadyResponse>;
/**
* Cancel an existing job.
*/
cancel(key: string): Promise<boolean>;
/**
* Retry a previous job using the same parameters.
*/
retry(params: RetryParams): Promise<ImageResponseWithRetry>;
/**
* Restart the image job workers.
*/
restart(): Promise<boolean>;
/**
* Check the status of the image job workers.
*/
status(): Promise<Array<unknown>>;
}

View File

@ -1,5 +1,6 @@
import { doesExist } from '@apextoaster/js-utils';
import { ChainPipeline, HighresParams, ModelParams, Txt2ImgParams, UpscaleParams } from './types.js';
import { HighresParams, ModelParams, Txt2ImgParams, UpscaleParams } from '../types/params.js';
import { ChainPipeline } from '../types/chain.js';
export interface PipelineVariable {
parameter: 'prompt' | 'cfg' | 'seed' | 'steps' | 'eta' | 'scheduler' | 'token';
@ -39,7 +40,7 @@ export function replacePromptTokens(grid: PipelineGrid, params: Txt2ImgParams, c
}
// eslint-disable-next-line max-params
export function buildPipelineForTxt2ImgGrid(grid: PipelineGrid, model: ModelParams, params: Txt2ImgParams, upscale?: UpscaleParams, highres?: HighresParams): ChainPipeline {
export function makeTxt2ImgGridPipeline(grid: PipelineGrid, model: ModelParams, params: Txt2ImgParams, upscale?: UpscaleParams, highres?: HighresParams): ChainPipeline {
const pipeline: ChainPipeline = {
defaults: {
...model,

View File

@ -21,9 +21,10 @@ import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow';
import { BaseImgParams, HighresParams, ImageMetadata, Txt2ImgParams, UpscaleParams } from '../client/types.js';
import { OnnxState, StateContext } from '../state.js';
import { DeepPartial } from '../types.js';
import { ImageMetadata } from '../types/api.js';
import { DeepPartial } from '../types/model.js';
import { BaseImgParams, HighresParams, Txt2ImgParams, UpscaleParams } from '../types/params.js';
const { useState } = React;

View File

@ -9,8 +9,8 @@ import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow';
import { ImageResponse, ReadyResponse, RetryParams } from '../../client/types.js';
import { ClientContext, ConfigContext, OnnxState, StateContext } from '../../state.js';
import { ImageResponse, ReadyResponse, RetryParams } from '../../types/api.js';
export interface ErrorCardProps {
image: ImageResponse;

View File

@ -8,8 +8,8 @@ import { useHash } from 'react-use/lib/useHash';
import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow';
import { ImageResponse } from '../../client/types.js';
import { BLEND_SOURCES, ConfigContext, OnnxState, StateContext } from '../../state.js';
import { ImageResponse } from '../../types/api.js';
import { range, visibleIndex } from '../../utils.js';
export interface ImageCardProps {

View File

@ -8,9 +8,9 @@ import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow';
import { ImageResponse } from '../../client/types.js';
import { POLL_TIME } from '../../config.js';
import { ClientContext, ConfigContext, OnnxState, StateContext } from '../../state.js';
import { ImageResponse } from '../../types/api.js';
const LOADING_PERCENT = 100;
const LOADING_OVERAGE = 99;

View File

@ -5,8 +5,8 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { HighresParams } from '../../client/types.js';
import { ConfigContext, OnnxState, StateContext } from '../../state.js';
import { HighresParams } from '../../types/params.js';
import { NumericField } from '../input/NumericField.js';
export interface HighresControlProps {

View File

@ -9,9 +9,9 @@ import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow';
import { BaseImgParams } from '../../client/types.js';
import { STALE_TIME } from '../../config.js';
import { ClientContext, ConfigContext, OnnxState, StateContext } from '../../state.js';
import { BaseImgParams } from '../../types/params.js';
import { NumericField } from '../input/NumericField.js';
import { PromptInput } from '../input/PromptInput.js';
import { QueryList } from '../input/QueryList.js';

View File

@ -5,9 +5,9 @@ import * as React from 'react';
import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { ModelParams } from '../../client/types.js';
import { STALE_TIME } from '../../config.js';
import { ClientContext } from '../../state.js';
import { ModelParams } from '../../types/params.js';
import { QueryList } from '../input/QueryList.js';
export interface ModelControlProps {

View File

@ -5,8 +5,8 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { UpscaleParams } from '../../client/types.js';
import { ConfigContext, OnnxState, StateContext } from '../../state.js';
import { UpscaleParams } from '../../types/params.js';
import { NumericField } from '../input/NumericField.js';
export interface UpscaleControlProps {

View File

@ -5,9 +5,9 @@ import { throttle } from 'lodash';
import React, { RefObject, useContext, useEffect, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { BrushParams } from '../../client/types.js';
import { SAVE_TIME } from '../../config.js';
import { ConfigContext, LoggerContext, StateContext } from '../../state.js';
import { BrushParams } from '../../types/params.js';
import { imageFromBlob } from '../../utils.js';
import { NumericField } from './NumericField';

View File

@ -2,7 +2,7 @@ import { Button, MenuItem, Select, Stack, TextField } from '@mui/material';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { CorrectionArch, CorrectionModel, ModelFormat } from '../../../types.js';
import { CorrectionArch, CorrectionModel, ModelFormat } from '../../../types/model.js';
export interface CorrectionModelInputProps {
key?: number | string;

View File

@ -2,7 +2,7 @@ import { Button, MenuItem, Select, Stack, TextField } from '@mui/material';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { DiffusionModel, ModelFormat } from '../../../types.js';
import { DiffusionModel, ModelFormat } from '../../../types/model.js';
export interface DiffusionModelInputProps {
key?: number | string;

View File

@ -2,7 +2,7 @@ import { Button, MenuItem, Select, Stack, TextField } from '@mui/material';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { ExtraNetwork, ModelFormat, NetworkModel, NetworkType } from '../../../types.js';
import { ExtraNetwork, ModelFormat, NetworkModel, NetworkType } from '../../../types/model.js';
export interface ExtraNetworkInputProps {
key?: number | string;

View File

@ -2,7 +2,7 @@ import { Button, MenuItem, Select, Stack, TextField } from '@mui/material';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { AnyFormat, ExtraSource } from '../../../types.js';
import { AnyFormat, ExtraSource } from '../../../types/model.js';
export interface ExtraSourceInputProps {
key?: number | string;

View File

@ -2,7 +2,7 @@ import { Button, MenuItem, Select, Stack, TextField } from '@mui/material';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { ModelFormat, UpscalingArch, UpscalingModel } from '../../../types.js';
import { ModelFormat, UpscalingArch, UpscalingModel } from '../../../types/model.js';
import { NumericField } from '../NumericField.js';
export interface UpscalingModelInputProps {

View File

@ -7,9 +7,9 @@ import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow';
import { BlendParams, BrushParams, ModelParams, UpscaleParams } from '../../client/types.js';
import { IMAGE_FILTER } from '../../config.js';
import { BLEND_SOURCES, ClientContext, OnnxState, StateContext, TabState } from '../../state.js';
import { BlendParams, BrushParams, ModelParams, UpscaleParams } from '../../types/params.js';
import { range } from '../../utils.js';
import { UpscaleControl } from '../control/UpscaleControl.js';
import { ImageInput } from '../input/ImageInput.js';

View File

@ -5,11 +5,12 @@ import * as React from 'react';
import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { shallow} from 'zustand/shallow';
import { shallow } from 'zustand/shallow';
import { HighresParams, Img2ImgParams, ModelParams, UpscaleParams } from '../../client/types.js';
import { IMAGE_FILTER, STALE_TIME } from '../../config.js';
import { ClientContext, ConfigContext, OnnxState, StateContext, TabState } from '../../state.js';
import { HighresParams, Img2ImgParams, ModelParams, UpscaleParams } from '../../types/params.js';
import { Profiles } from '../Profiles.js';
import { HighresControl } from '../control/HighresControl.js';
import { ImageControl } from '../control/ImageControl.js';
import { ModelControl } from '../control/ModelControl.js';
@ -17,7 +18,6 @@ import { UpscaleControl } from '../control/UpscaleControl.js';
import { ImageInput } from '../input/ImageInput.js';
import { NumericField } from '../input/NumericField.js';
import { QueryList } from '../input/QueryList.js';
import { Profiles } from '../Profiles.js';
export function Img2Img() {
const { params } = mustExist(useContext(ConfigContext));

View File

@ -7,9 +7,10 @@ import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow';
import { BrushParams, HighresParams, InpaintParams, ModelParams, UpscaleParams } from '../../client/types.js';
import { IMAGE_FILTER, STALE_TIME } from '../../config.js';
import { ClientContext, ConfigContext, OnnxState, StateContext, TabState } from '../../state.js';
import { BrushParams, HighresParams, InpaintParams, ModelParams, UpscaleParams } from '../../types/params.js';
import { Profiles } from '../Profiles.js';
import { HighresControl } from '../control/HighresControl.js';
import { ImageControl } from '../control/ImageControl.js';
import { ModelControl } from '../control/ModelControl.js';
@ -19,7 +20,6 @@ import { ImageInput } from '../input/ImageInput.js';
import { MaskCanvas } from '../input/MaskCanvas.js';
import { NumericField } from '../input/NumericField.js';
import { QueryList } from '../input/QueryList.js';
import { Profiles } from '../Profiles.js';
export function Inpaint() {
const { params } = mustExist(useContext(ConfigContext));

View File

@ -19,7 +19,7 @@ import {
NetworkType,
SafetensorFormat,
UpscalingModel,
} from '../../types.js';
} from '../../types/model.js';
import { EditableList } from '../input/EditableList';
import { CorrectionModelInput } from '../input/model/CorrectionModel.js';
import { DiffusionModelInput } from '../input/model/DiffusionModel.js';

View File

@ -7,16 +7,16 @@ import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow';
import { HighresParams, ModelParams, Txt2ImgParams, UpscaleParams } from '../../client/types.js';
import { PipelineGrid, makeTxt2ImgGridPipeline } from '../../client/utils.js';
import { ClientContext, ConfigContext, OnnxState, StateContext, TabState } from '../../state.js';
import { HighresParams, ModelParams, Txt2ImgParams, UpscaleParams } from '../../types/params.js';
import { Profiles } from '../Profiles.js';
import { HighresControl } from '../control/HighresControl.js';
import { ImageControl } from '../control/ImageControl.js';
import { ModelControl } from '../control/ModelControl.js';
import { UpscaleControl } from '../control/UpscaleControl.js';
import { NumericField } from '../input/NumericField.js';
import { Profiles } from '../Profiles.js';
import { VariableControl } from '../control/VariableControl.js';
import { PipelineGrid, buildPipelineForTxt2ImgGrid } from '../../client/utils.js';
import { NumericField } from '../input/NumericField.js';
export function Txt2Img() {
const { params } = mustExist(useContext(ConfigContext));
@ -29,7 +29,7 @@ export function Txt2Img() {
const highres = selectHighres(state);
if (grid.enabled) {
const chain = buildPipelineForTxt2ImgGrid(grid, model, params2, upscale, highres);
const chain = makeTxt2ImgGridPipeline(grid, model, params2, upscale, highres);
const image = await client.chain(model, chain);
pushHistory(image);
} else {

View File

@ -7,15 +7,15 @@ import { useTranslation } from 'react-i18next';
import { useStore } from 'zustand';
import { shallow } from 'zustand/shallow';
import { HighresParams, ModelParams, UpscaleParams, UpscaleReqParams } from '../../client/types.js';
import { IMAGE_FILTER } from '../../config.js';
import { ClientContext, OnnxState, StateContext, TabState } from '../../state.js';
import { HighresParams, ModelParams, UpscaleParams, UpscaleReqParams } from '../../types/params.js';
import { Profiles } from '../Profiles.js';
import { HighresControl } from '../control/HighresControl.js';
import { ModelControl } from '../control/ModelControl.js';
import { UpscaleControl } from '../control/UpscaleControl.js';
import { ImageInput } from '../input/ImageInput.js';
import { PromptInput } from '../input/PromptInput.js';
import { Profiles } from '../Profiles.js';
export function Upscale() {
async function uploadSource() {

View File

@ -10,7 +10,7 @@ import {
OutpaintParams,
Txt2ImgParams,
UpscaleParams,
} from './client/types.js';
} from './types/params.js';
export interface ConfigBoolean {
default: boolean;

View File

@ -12,7 +12,7 @@ import { createJSONStorage, persist } from 'zustand/middleware';
import { makeClient } from './client/api.js';
import { LOCAL_CLIENT } from './client/local.js';
import { ApiClient } from './client/types.js';
import { ApiClient } from './client/base.js';
import { ParamsVersionError } from './components/error/ParamsVersion.js';
import { ServerParamsError } from './components/error/ServerParams.js';
import { LoadingScreen } from './components/LoadingScreen.js';

View File

@ -8,24 +8,24 @@ import { StateCreator, StoreApi } from 'zustand';
import {
ApiClient,
} from './client/base.js';
import { PipelineGrid } from './client/utils.js';
import { Config, ConfigFiles, ConfigState, ServerParams } from './config.js';
import { CorrectionModel, DiffusionModel, ExtraNetwork, ExtraSource, ExtrasFile, UpscalingModel } from './types/model.js';
import { ImageResponse, ReadyResponse, RetryParams } from './types/api.js';
import {
BaseImgParams,
BlendParams,
BrushParams,
HighresParams,
ImageResponse,
Img2ImgParams,
InpaintParams,
ModelParams,
OutpaintPixels,
ReadyResponse,
RetryParams,
Txt2ImgParams,
UpscaleParams,
UpscaleReqParams,
} from './client/types.js';
import { Config, ConfigFiles, ConfigState, ServerParams } from './config.js';
import { CorrectionModel, DiffusionModel, ExtraNetwork, ExtraSource, ExtrasFile, UpscalingModel } from './types.js';
import { PipelineGrid } from './client/utils.js';
} from './types/params.js';
export const MISSING_INDEX = -1;

120
gui/src/types/api.ts Normal file
View File

@ -0,0 +1,120 @@
import {
BaseImgParams,
ModelParams,
Txt2ImgParams,
UpscaleParams,
HighresParams,
Img2ImgParams,
InpaintParams,
OutpaintParams,
UpscaleReqParams,
BlendParams,
ImageSize,
} from './params.js';
/**
* Output image data within the response.
*/
export interface ImageOutput {
key: string;
url: string;
}
/**
* General response for most image requests.
*/
export interface ImageResponse {
outputs: Array<ImageOutput>;
params: Required<BaseImgParams> & Required<ModelParams>;
size: ImageSize;
}
/**
* Status response from the ready endpoint.
*/
export interface ReadyResponse {
cancelled: boolean;
failed: boolean;
progress: number;
ready: boolean;
}
export interface NetworkModel {
name: string;
type: 'control' | 'inversion' | 'lora';
// TODO: add token
// TODO: add layer/token count
}
export interface FilterResponse {
mask: Array<string>;
source: Array<string>;
}
/**
* List of available models.
*/
export interface ModelResponse {
correction: Array<string>;
diffusion: Array<string>;
networks: Array<NetworkModel>;
upscaling: Array<string>;
}
export interface WriteExtrasResponse {
file: string;
successful: Array<string>;
errors: Array<string>;
}
export type RetryParams = {
type: 'txt2img';
model: ModelParams;
params: Txt2ImgParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'img2img';
model: ModelParams;
params: Img2ImgParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'inpaint';
model: ModelParams;
params: InpaintParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'outpaint';
model: ModelParams;
params: OutpaintParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'upscale';
model: ModelParams;
params: UpscaleReqParams;
upscale?: UpscaleParams;
highres?: HighresParams;
} | {
type: 'blend';
model: ModelParams;
params: BlendParams;
upscale?: UpscaleParams;
};
export interface ImageResponseWithRetry {
image: ImageResponse;
retry: RetryParams;
}
export interface ImageMetadata {
highres: HighresParams;
outputs: string | Array<string>;
params: Txt2ImgParams | Img2ImgParams | InpaintParams;
upscale: UpscaleParams;
input_size: ImageSize;
size: ImageSize;
}

40
gui/src/types/chain.ts Normal file
View File

@ -0,0 +1,40 @@
import { ImageSize, Img2ImgParams, ModelParams, Txt2ImgParams } from './params.js';
export interface ChainStageParams {
tile_size: number;
}
export interface Txt2ImgStage {
name: string;
type: 'source-txt2img';
params: Partial<Txt2ImgParams & ChainStageParams>;
}
export interface Img2ImgStage {
name: string;
type: 'blend-img2img';
params: Partial<Img2ImgParams & ChainStageParams>;
}
export interface GridStage {
name: string;
type: 'blend-grid';
params: Partial<ImageSize & ChainStageParams>;
}
export interface OutputStage {
name: string;
type: 'persist-disk';
params: Partial<ChainStageParams>;
}
export interface ChainPipeline {
/* defaults?: {
txt2img?: Txt2ImgParams;
img2img?: Img2ImgParams;
}; */
defaults?: Txt2ImgParams & ModelParams;
stages: Array<Txt2ImgStage | Img2ImgStage | GridStage | OutputStage>;
}

165
gui/src/types/params.ts Normal file
View File

@ -0,0 +1,165 @@
/**
* Output image size, after upscaling and outscale.
*/
export interface ImageSize {
width: number;
height: number;
}
/**
* Shared parameters for anything using models, which is pretty much everything.
*/
export interface ModelParams {
/**
* The diffusion model to use.
*/
model: string;
/**
* Specialized pipeline to use.
*/
pipeline: string;
/**
* The hardware acceleration platform to use.
*/
platform: string;
/**
* The upscaling model to use.
*/
upscaling: string;
/**
* The correction model to use.
*/
correction: string;
/**
* ControlNet to be used.
*/
control: string;
}
/**
* Shared parameters for most of the image requests.
*/
export interface BaseImgParams {
scheduler: string;
prompt: string;
negativePrompt?: string;
batch: number;
tiledVAE: boolean;
tiles: number;
overlap: number;
stride: number;
cfg: number;
steps: number;
seed: number;
eta: number;
}
/**
* Parameters for txt2img requests.
*/
export type Txt2ImgParams = BaseImgParams & ImageSize;
/**
* Parameters for img2img requests.
*/
export interface Img2ImgParams extends BaseImgParams {
source: Blob;
loopback: number;
sourceFilter: string;
strength: number;
}
/**
* Parameters for inpaint requests.
*/
export interface InpaintParams extends BaseImgParams {
mask: Blob;
source: Blob;
filter: string;
noise: string;
strength: number;
fillColor: string;
tileOrder: string;
}
/**
* Additional parameters for outpaint border.
*
* @todo should be nested under inpaint/outpaint params
*/
export interface OutpaintPixels {
enabled: boolean;
left: number;
right: number;
top: number;
bottom: number;
}
/**
* Parameters for outpaint requests.
*/
export type OutpaintParams = InpaintParams & OutpaintPixels;
/**
* Additional parameters for the inpaint brush.
*
* These are not currently sent to the server and only stored in state.
*
* @todo move to state
*/
export interface BrushParams {
color: number;
size: number;
strength: number;
}
/**
* Additional parameters for upscaling. May be sent with most other requests to run a post-pipeline.
*/
export interface UpscaleParams {
enabled: boolean;
upscaleOrder: string;
denoise: number;
scale: number;
outscale: number;
faces: boolean;
faceStrength: number;
faceOutscale: number;
}
/**
* Parameters for upscale requests.
*/
export interface UpscaleReqParams extends BaseImgParams {
source: Blob;
}
/**
* Parameters for blend requests.
*/
export interface BlendParams {
sources: Array<Blob>;
mask: Blob;
}
export interface HighresParams {
enabled: boolean;
highresIterations: number;
highresMethod: string;
highresScale: number;
highresSteps: number;
highresStrength: number;
}