Skip to content

Commit

Permalink
feat(gui): add menus for noise source and blend mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 15, 2023
1 parent a8f0a7a commit d3ad43b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
19 changes: 19 additions & 0 deletions gui/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export type Txt2ImgResponse = Required<Txt2ImgParams>;
export interface InpaintParams extends BaseImgParams {
mask: Blob;
source: Blob;

blend: string;
noise: string;
}

export interface OutpaintPixels {
Expand Down Expand Up @@ -75,7 +78,9 @@ export interface ApiReady {
}

export interface ApiClient {
blends(): Promise<Array<string>>;
models(): Promise<Array<string>>;
noises(): Promise<Array<string>>;
params(): Promise<ConfigParams>;
platforms(): Promise<Array<string>>;
schedulers(): Promise<Array<string>>;
Expand Down Expand Up @@ -156,11 +161,21 @@ export function makeClient(root: string, f = fetch): ApiClient {
}

return {
async blends(): Promise<Array<string>> {
const path = makeApiUrl(root, 'settings', 'blends');
const res = await f(path);
return await res.json() as Array<string>;
},
async models(): Promise<Array<string>> {
const path = makeApiUrl(root, 'settings', 'models');
const res = await f(path);
return await res.json() as Array<string>;
},
async noises(): Promise<Array<string>> {
const path = makeApiUrl(root, 'settings', 'noises');
const res = await f(path);
return await res.json() as Array<string>;
},
async params(): Promise<ConfigParams> {
const path = makeApiUrl(root, 'settings', 'params');
const res = await f(path);
Expand Down Expand Up @@ -223,6 +238,8 @@ export function makeClient(root: string, f = fetch): ApiClient {
}

const url = makeImageURL(root, 'inpaint', params);
url.searchParams.append('noise', params.noise);
url.searchParams.append('blend', params.blend);

const body = new FormData();
body.append('mask', params.mask, 'mask');
Expand All @@ -242,6 +259,8 @@ export function makeClient(root: string, f = fetch): ApiClient {
}

const url = makeImageURL(root, 'inpaint', params);
url.searchParams.append('noise', params.noise);
url.searchParams.append('blend', params.blend);

if (doesExist(params.left)) {
url.searchParams.append('left', params.left.toFixed(0));
Expand Down
36 changes: 34 additions & 2 deletions gui/src/components/Inpaint.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { mustExist } from '@apextoaster/js-utils';
import { Box, Button, Stack } from '@mui/material';
import * as React from 'react';
import { useMutation, useQueryClient } from 'react-query';
import { useMutation, useQuery, useQueryClient } from 'react-query';
import { useStore } from 'zustand';

import { ConfigParams, IMAGE_FILTER } from '../config.js';
import { ConfigParams, IMAGE_FILTER, STALE_TIME } from '../config.js';
import { ClientContext, StateContext } from '../state.js';
import { BLEND_LABELS, NOISE_LABELS } from '../strings.js';
import { ImageControl } from './ImageControl.js';
import { ImageInput } from './ImageInput.js';
import { MaskCanvas } from './MaskCanvas.js';
import { OutpaintControl } from './OutpaintControl.js';
import { QueryList } from './QueryList.js';

const { useContext } = React;

Expand All @@ -23,6 +25,12 @@ export interface InpaintProps {
export function Inpaint(props: InpaintProps) {
const { config, model, platform } = props;
const client = mustExist(useContext(ClientContext));
const blends = useQuery('blends', async () => client.blends(), {
staleTime: STALE_TIME,
});
const noises = useQuery('noises', async () => client.noises(), {
staleTime: STALE_TIME,
});

async function uploadSource(): Promise<void> {
const outpaint = state.getState().outpaint; // TODO: seems shady
Expand Down Expand Up @@ -104,6 +112,30 @@ export function Inpaint(props: InpaintProps) {
setInpaint(newParams);
}}
/>
<QueryList
id='blends'
labels={BLEND_LABELS}
name='Blend Mode'
result={blends}
value={params.blend}
onChange={(blend) => {
setInpaint({
blend,
});
}}
/>
<QueryList
id='noises'
labels={NOISE_LABELS}
name='Noise Source'
result={noises}
value={params.noise}
onChange={(noise) => {
setInpaint({
noise,
});
}}
/>
<OutpaintControl config={config} />
<Button onClick={() => upload.mutate()}>Generate</Button>
</Stack>
Expand Down
4 changes: 4 additions & 0 deletions gui/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export function createStateSlices(base: ConfigParams) {
...defaults,
mask: null,
source: null,
noise: '',
blend: '',
},
setInpaint(params) {
set((prev) => ({
Expand All @@ -143,6 +145,8 @@ export function createStateSlices(base: ConfigParams) {
...defaults,
mask: null,
source: null,
noise: '',
blend: '',
},
});
},
Expand Down
13 changes: 13 additions & 0 deletions gui/src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ export const SCHEDULER_LABELS: Record<string, string> = {
'lms-discrete': 'LMS',
'pndm': 'PNDM',
};

export const NOISE_LABELS: Record<string, string> = {
fill: 'Fill Edges',
guassian: 'Gaussian Blur',
histogram: 'Histogram Noise',
normal: 'Gaussian Noise',
uniform: 'Uniform Noise',
};

export const BLEND_LABELS: Record<string, string> = {
'mask-source': 'Noise -> Source',
'source-mask': 'Source -> Noise',
};

0 comments on commit d3ad43b

Please sign in to comment.