1
0
Fork 0

update image card for multiple outputs

This commit is contained in:
Sean Sube 2023-02-21 08:15:00 -06:00
parent 82016a163a
commit 5b1411e783
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
5 changed files with 21 additions and 21 deletions

View File

@ -145,7 +145,7 @@ export interface BlendParams {
* General response for most image requests. * General response for most image requests.
*/ */
export interface ImageResponse { export interface ImageResponse {
output: Array<{ outputs: Array<{
key: string; key: string;
url: string; url: string;
}>; }>;
@ -258,7 +258,7 @@ export const FIXED_FLOAT = 2;
export const STATUS_SUCCESS = 200; export const STATUS_SUCCESS = 200;
export function equalResponse(a: ImageResponse, b: ImageResponse): boolean { export function equalResponse(a: ImageResponse, b: ImageResponse): boolean {
return a.output === b.output; return a.outputs === b.outputs;
} }
/** /**
@ -546,12 +546,12 @@ export function makeClient(root: string, f = fetch): ApiClient {
* that into a full URL, since it already knows the root URL of the server. * that into a full URL, since it already knows the root URL of the server.
*/ */
export async function parseApiResponse(root: string, res: Response): Promise<ImageResponse> { export async function parseApiResponse(root: string, res: Response): Promise<ImageResponse> {
type LimitedResponse = Omit<ImageResponse, 'output'> & { output: Array<string> }; type LimitedResponse = Omit<ImageResponse, 'outputs'> & { outputs: Array<string> };
if (res.status === STATUS_SUCCESS) { if (res.status === STATUS_SUCCESS) {
const data = await res.json() as LimitedResponse; const data = await res.json() as LimitedResponse;
const images = data.output.map((output) => { const outputs = data.outputs.map((output) => {
const url = new URL(joinPath('output', output), root).toString(); const url = new URL(joinPath('output', output), root).toString();
return { return {
key: output, key: output,
@ -561,7 +561,7 @@ export async function parseApiResponse(root: string, res: Response): Promise<Ima
return { return {
...data, ...data,
output: images, outputs,
}; };
} else { } else {
throw new Error('request error'); throw new Error('request error');

View File

@ -25,7 +25,7 @@ export function GridItem(props: { xs: number; children: React.ReactNode }) {
export function ImageCard(props: ImageCardProps) { export function ImageCard(props: ImageCardProps) {
const { value } = props; const { value } = props;
const { params, output, size } = value; const { params, outputs, size } = value;
const [_hash, setHash] = useHash(); const [_hash, setHash] = useHash();
const [anchor, setAnchor] = useState<Maybe<HTMLElement>>(); const [anchor, setAnchor] = useState<Maybe<HTMLElement>>();
@ -42,7 +42,7 @@ export function ImageCard(props: ImageCardProps) {
const setBlend = useStore(state, (s) => s.setBlend); const setBlend = useStore(state, (s) => s.setBlend);
async function loadSource() { async function loadSource() {
const req = await fetch(output[0].url); const req = await fetch(outputs[index].url);
return req.blob(); return req.blob();
} }
@ -88,7 +88,7 @@ export function ImageCard(props: ImageCardProps) {
} }
function downloadImage() { function downloadImage() {
window.open(output[0].url, '_blank'); window.open(outputs[index].url, '_blank');
} }
function close() { function close() {
@ -103,7 +103,7 @@ export function ImageCard(props: ImageCardProps) {
return <Card sx={{ maxWidth: config.params.width.default }} elevation={2}> return <Card sx={{ maxWidth: config.params.width.default }} elevation={2}>
<CardMedia sx={{ height: config.params.height.default }} <CardMedia sx={{ height: config.params.height.default }}
component='img' component='img'
image={output[index].url} image={outputs[index].url}
title={params.prompt} title={params.prompt}
/> />
<CardContent> <CardContent>
@ -114,7 +114,7 @@ export function ImageCard(props: ImageCardProps) {
<IconButton onClick={() => { <IconButton onClick={() => {
const prevIndex = index - 1; const prevIndex = index - 1;
if (prevIndex < 0) { if (prevIndex < 0) {
setIndex(output.length + prevIndex); setIndex(outputs.length + prevIndex);
} else { } else {
setIndex(prevIndex); setIndex(prevIndex);
} }
@ -124,12 +124,12 @@ export function ImageCard(props: ImageCardProps) {
</Tooltip> </Tooltip>
</GridItem> </GridItem>
<GridItem xs={4}> <GridItem xs={4}>
{visibleIndex(index)} of {output.length} {visibleIndex(index)} of {outputs.length}
</GridItem> </GridItem>
<GridItem xs={4}> <GridItem xs={4}>
<Tooltip title='Next'> <Tooltip title='Next'>
<IconButton onClick={() => { <IconButton onClick={() => {
setIndex((index + 1) % output.length); setIndex((index + 1) % outputs.length);
}}> }}>
<ArrowRight /> <ArrowRight />
</IconButton> </IconButton>

View File

@ -18,11 +18,11 @@ export function ImageHistory() {
const children = []; const children = [];
if (loading.length > 0) { if (loading.length > 0) {
children.push(...loading.map((item) => <LoadingCard key={`loading-${item.image.output[0].key}`} index={0} loading={item.image} />)); children.push(...loading.map((item) => <LoadingCard key={`loading-${item.image.outputs[0].key}`} index={0} loading={item.image} />));
} }
if (history.length > 0) { if (history.length > 0) {
children.push(...history.map((item) => <ImageCard key={`history-${item.output[0].key}`} value={item} onDelete={removeHistory} />)); children.push(...history.map((item) => <ImageCard key={`history-${item.outputs[0].key}`} value={item} onDelete={removeHistory} />));
} else { } else {
if (doesExist(loading) === false) { if (doesExist(loading) === false) {
children.push(<Typography>No results. Press Generate.</Typography>); children.push(<Typography>No results. Press Generate.</Typography>);

View File

@ -33,8 +33,8 @@ export function LoadingCard(props: LoadingCardProps) {
// eslint-disable-next-line @typescript-eslint/unbound-method // eslint-disable-next-line @typescript-eslint/unbound-method
const setReady = useStore(state, (s) => s.setReady); const setReady = useStore(state, (s) => s.setReady);
const cancel = useMutation(() => client.cancel(loading.output[index].key)); const cancel = useMutation(() => client.cancel(loading.outputs[index].key));
const ready = useQuery(`ready-${loading.output[index].key}`, () => client.ready(loading.output[index].key), { const ready = useQuery(`ready-${loading.outputs[index].key}`, () => client.ready(loading.outputs[index].key), {
// data will always be ready without this, even if the API says its not // data will always be ready without this, even if the API says its not
cacheTime: 0, cacheTime: 0,
refetchInterval: POLL_TIME, refetchInterval: POLL_TIME,

View File

@ -164,7 +164,7 @@ export const STATE_KEY = 'onnx-web';
/** /**
* Current state version for zustand persistence. * Current state version for zustand persistence.
*/ */
export const STATE_VERSION = 5; export const STATE_VERSION = 6;
export const BLEND_SOURCES = 2; export const BLEND_SOURCES = 2;
@ -311,7 +311,7 @@ export function createStateSlices(server: ServerParams) {
clearLoading(image) { clearLoading(image) {
set((prev) => ({ set((prev) => ({
...prev, ...prev,
loading: prev.loading.filter((it) => it.image.output[0].key !== image.output[0].key), loading: prev.loading.filter((it) => it.image.outputs[0].key !== image.outputs[0].key),
})); }));
}, },
pushHistory(image) { pushHistory(image) {
@ -321,7 +321,7 @@ export function createStateSlices(server: ServerParams) {
image, image,
...prev.history, ...prev.history,
].slice(0, prev.limit + DEFAULT_HISTORY.scrollback), ].slice(0, prev.limit + DEFAULT_HISTORY.scrollback),
loading: prev.loading.filter((it) => it.image.output[0].key !== image.output[0].key), loading: prev.loading.filter((it) => it.image.outputs[0].key !== image.outputs[0].key),
})); }));
}, },
pushLoading(image) { pushLoading(image) {
@ -342,7 +342,7 @@ export function createStateSlices(server: ServerParams) {
removeHistory(image) { removeHistory(image) {
set((prev) => ({ set((prev) => ({
...prev, ...prev,
history: prev.history.filter((it) => it.output !== image.output), history: prev.history.filter((it) => it.outputs !== image.outputs),
})); }));
}, },
setLimit(limit) { setLimit(limit) {
@ -354,7 +354,7 @@ export function createStateSlices(server: ServerParams) {
setReady(image, ready) { setReady(image, ready) {
set((prev) => { set((prev) => {
const loading = [...prev.loading]; const loading = [...prev.loading];
const idx = loading.findIndex((it) => it.image.output[0].key === image.output[0].key); const idx = loading.findIndex((it) => it.image.outputs[0].key === image.outputs[0].key);
if (idx >= 0) { if (idx >= 0) {
loading[idx].ready = ready; loading[idx].ready = ready;
} else { } else {