Skip to content

Commit

Permalink
fix(gui): read image size from its own field
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 16, 2023
1 parent 13a4fa2 commit 4d6560a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 6 additions & 2 deletions gui/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export interface ApiResponse {
key: string;
url: string;
};
params: Txt2ImgResponse;
params: Required<BaseImgParams>;
size: {
width: number;
height: number;
};
}

export interface ApiReady {
Expand Down Expand Up @@ -307,11 +311,11 @@ export async function parseApiResponse(root: string, res: Response): Promise<Api
const data = await res.json() as LimitedResponse;
const url = makeApiUrl(root, 'output', data.output).toString();
return {
...data,
output: {
key: data.output,
url,
},
params: data.params,
};
} else {
throw new Error('request error');
Expand Down
8 changes: 4 additions & 4 deletions gui/src/components/ImageCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function GridItem(props: { xs: number; children: React.ReactNode }) {

export function ImageCard(props: ImageCardProps) {
const { value } = props;
const { params, output } = value;
const { params, output, size } = value;

const state = mustExist(useContext(StateContext));
// eslint-disable-next-line @typescript-eslint/unbound-method
Expand Down Expand Up @@ -59,8 +59,8 @@ export function ImageCard(props: ImageCardProps) {
window.open(output.url, '_blank');
}

return <Card sx={{ maxWidth: params.width }} elevation={2}>
<CardMedia sx={{ height: params.height }}
return <Card sx={{ maxWidth: size.width }} elevation={2}>
<CardMedia sx={{ height: size.height }}
component='img'
image={output.url}
title={params.prompt}
Expand All @@ -70,7 +70,7 @@ export function ImageCard(props: ImageCardProps) {
<Grid container spacing={2}>
<GridItem xs={4}>CFG: {params.cfg}</GridItem>
<GridItem xs={4}>Steps: {params.steps}</GridItem>
<GridItem xs={4}>Size: {params.width}x{params.height}</GridItem>
<GridItem xs={4}>Size: {size.width}x{size.height}</GridItem>
<GridItem xs={4}>Seed: {params.seed}</GridItem>
<GridItem xs={8}>Scheduler: {params.scheduler}</GridItem>
<GridItem xs={12}>{params.prompt}</GridItem>
Expand Down
6 changes: 3 additions & 3 deletions gui/src/components/LoadingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export function LoadingCard(props: LoadingCardProps) {
}
}, [ready.status, ready.data?.ready]);

return <Card sx={{ maxWidth: props.loading.params.width }}>
<CardContent sx={{ height: props.loading.params.height }}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: props.loading.params.height }}>
return <Card sx={{ maxWidth: props.loading.size.width }}>
<CardContent sx={{ height: props.loading.size.height }}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: props.loading.size.height }}>
<CircularProgress />
</div>
</CardContent>
Expand Down

0 comments on commit 4d6560a

Please sign in to comment.