mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-06-19 17:39:16 +02:00
loading and cache are better
This commit is contained in:
parent
c4718bd302
commit
9d220c482d
@ -35,6 +35,7 @@ module.exports = {
|
|||||||
yoda: ["off"],
|
yoda: ["off"],
|
||||||
eqeqeq: ["off"],
|
eqeqeq: ["off"],
|
||||||
"spaced-comment": ["off"],
|
"spaced-comment": ["off"],
|
||||||
|
"padded-blocks": ["off"],
|
||||||
|
|
||||||
// TS things turned off for now
|
// TS things turned off for now
|
||||||
"@typescript-eslint/ban-ts-comment": "off",
|
"@typescript-eslint/ban-ts-comment": "off",
|
||||||
|
@ -59,7 +59,6 @@ export const toggleBetaConfig = async (branch: string) => {
|
|||||||
|
|
||||||
export const MakeImageKey = "MakeImage";
|
export const MakeImageKey = "MakeImage";
|
||||||
export const doMakeImage = async (reqBody: ImageRequest) => {
|
export const doMakeImage = async (reqBody: ImageRequest) => {
|
||||||
const { seed, num_outputs } = reqBody;
|
|
||||||
|
|
||||||
const res = await fetch(`${API_URL}/image`, {
|
const res = await fetch(`${API_URL}/image`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -8,8 +8,8 @@ import {
|
|||||||
} from "./generatedImage.css.ts";
|
} from "./generatedImage.css.ts";
|
||||||
|
|
||||||
interface GeneretaedImageProps {
|
interface GeneretaedImageProps {
|
||||||
imageData: string;
|
imageData: string | undefined;
|
||||||
metadata: ImageRequest;
|
metadata: ImageRequest | undefined;
|
||||||
className?: string;
|
className?: string;
|
||||||
// children: never[];
|
// children: never[];
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ export default function GeneratedImage({
|
|||||||
}: GeneretaedImageProps) {
|
}: GeneretaedImageProps) {
|
||||||
return (
|
return (
|
||||||
<div className={[generatedImageMain, className].join(" ")}>
|
<div className={[generatedImageMain, className].join(" ")}>
|
||||||
<img className={image} src={imageData} alt={metadata.prompt} />
|
<img className={image} src={imageData} alt={metadata!.prompt} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,6 @@ export default function ImprovementSettings() {
|
|||||||
const [isFilteringDisabled, setIsFilteringDisabled] = useState(false);
|
const [isFilteringDisabled, setIsFilteringDisabled] = useState(false);
|
||||||
// should probably be a store selector
|
// should probably be a store selector
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("isUsingUpscaling", isUsingUpscaling);
|
|
||||||
console.log("isUsingFaceCorrection", isUsingFaceCorrection);
|
|
||||||
|
|
||||||
// if either are true we arent disabled
|
// if either are true we arent disabled
|
||||||
if (isUsingFaceCorrection || use_upscale) {
|
if (isUsingFaceCorrection || use_upscale) {
|
||||||
|
@ -10,4 +10,6 @@ const AudioDing = React.forwardRef((props, ref) => (
|
|||||||
</audio>
|
</audio>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
AudioDing.displayName = "AudioDing";
|
||||||
|
|
||||||
export default AudioDing;
|
export default AudioDing;
|
||||||
|
@ -4,15 +4,37 @@ import { style, globalStyle } from "@vanilla-extract/css";
|
|||||||
import { vars } from "../../../../styles/theme/index.css.ts";
|
import { vars } from "../../../../styles/theme/index.css.ts";
|
||||||
|
|
||||||
export const completedImagesMain = style({
|
export const completedImagesMain = style({
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
display: "flex",
|
||||||
|
paddingBottom: vars.spacing.medium,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const completedImagesList = style({
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
flexWrap: "nowrap",
|
flexWrap: "nowrap",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
overflow: "auto",
|
overflow: "auto",
|
||||||
paddingBottom: vars.spacing.medium,
|
paddingLeft: vars.spacing.none,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
globalStyle(`${completedImagesMain} li`, {
|
||||||
|
|
||||||
|
position: "relative",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle(`${completedImagesMain} > li:first-of-type`, {
|
||||||
|
marginLeft: vars.spacing.medium,
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle(`${completedImagesMain} > li:last-of-type`, {
|
||||||
|
marginRight: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
export const imageContain = style({
|
export const imageContain = style({
|
||||||
width: "206px",
|
width: "206px",
|
||||||
backgroundColor: "black",
|
backgroundColor: "black",
|
||||||
@ -26,15 +48,18 @@ export const imageContain = style({
|
|||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
globalStyle(`${imageContain} img`, {
|
globalStyle(`${imageContain} img`, {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
objectFit: "contain",
|
objectFit: "contain",
|
||||||
});
|
});
|
||||||
|
|
||||||
globalStyle(`${completedImagesMain} > ${imageContain}:first-of-type`, {
|
export const RemoveButton = style({
|
||||||
marginLeft: vars.spacing.medium,
|
marginLeft: vars.spacing.small,
|
||||||
});
|
backgroundColor: vars.colors.brand,
|
||||||
|
border: "0 none",
|
||||||
globalStyle(`${imageContain} > ${imageContain}:last-of-type`, {
|
padding: vars.spacing.small,
|
||||||
marginRight: 0,
|
cursor: "pointer",
|
||||||
});
|
borderRadius: vars.trim.borderRadiusSmall,
|
||||||
|
});
|
@ -4,17 +4,22 @@ import { CompletedImagesType } from "../index";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
completedImagesMain,
|
completedImagesMain,
|
||||||
imageContain, // @ts-expect-error
|
completedImagesList,
|
||||||
|
imageContain,
|
||||||
|
RemoveButton,
|
||||||
|
// @ts-expect-error
|
||||||
} from "./completedImages.css.ts";
|
} from "./completedImages.css.ts";
|
||||||
|
|
||||||
interface CurrentDisplayProps {
|
interface CurrentDisplayProps {
|
||||||
images: CompletedImagesType[] | null;
|
images: CompletedImagesType[] | null;
|
||||||
setCurrentDisplay: (image: CompletedImagesType) => void;
|
setCurrentDisplay: (image: CompletedImagesType) => void;
|
||||||
|
removeImages: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CompletedImages({
|
export default function CompletedImages({
|
||||||
images,
|
images,
|
||||||
setCurrentDisplay,
|
setCurrentDisplay,
|
||||||
|
removeImages,
|
||||||
}: CurrentDisplayProps) {
|
}: CurrentDisplayProps) {
|
||||||
const _handleSetCurrentDisplay = (index: number) => {
|
const _handleSetCurrentDisplay = (index: number) => {
|
||||||
const image = images![index];
|
const image = images![index];
|
||||||
@ -23,25 +28,37 @@ export default function CompletedImages({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={completedImagesMain}>
|
<div className={completedImagesMain}>
|
||||||
{images != null &&
|
{/* Adjust the dom do we dont do this check twice */}
|
||||||
images.map((image, index) => {
|
{images != null && images.length > 0 && (
|
||||||
if (void 0 === image) {
|
<button className={RemoveButton} onClick={
|
||||||
console.warn(`image ${index} is undefined`);
|
() => {
|
||||||
return null;
|
removeImages();
|
||||||
}
|
}
|
||||||
|
}>REMOVE</button>
|
||||||
|
)}
|
||||||
|
<ul className={completedImagesList}>
|
||||||
|
{images != null &&
|
||||||
|
images.map((image, index) => {
|
||||||
|
if (void 0 === image) {
|
||||||
|
console.warn(`image ${index} is undefined`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<li key={image.id}>
|
||||||
key={index}
|
<button
|
||||||
className={imageContain}
|
className={imageContain}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
_handleSetCurrentDisplay(index);
|
_handleSetCurrentDisplay(index);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img src={image.data} alt={image.info.prompt} />
|
<img src={image.data} alt={image.info.prompt} />
|
||||||
</button>
|
</button>
|
||||||
);
|
</li>
|
||||||
})}
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,10 @@ interface CurrentDisplayProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function CurrentDisplay({ isLoading, image }: CurrentDisplayProps) {
|
export default function CurrentDisplay({ isLoading, image }: CurrentDisplayProps) {
|
||||||
// @ts-ignore
|
const { info, data } = image ?? {};
|
||||||
const { info, data } = image;
|
|
||||||
|
|
||||||
const setRequestOption = useImageCreate((state) => state.setRequestOptions);
|
const setRequestOption = useImageCreate((state) => state.setRequestOptions);
|
||||||
console.log('current data', data);
|
|
||||||
console.log('current info', info);
|
|
||||||
const createFileName = () => {
|
const createFileName = () => {
|
||||||
const {
|
const {
|
||||||
prompt,
|
prompt,
|
||||||
@ -29,9 +27,7 @@ export default function CurrentDisplay({ isLoading, image }: CurrentDisplayProps
|
|||||||
use_upscale,
|
use_upscale,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
} = info;
|
} = info!;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Most important information is the prompt
|
// Most important information is the prompt
|
||||||
@ -81,7 +77,6 @@ export default function CurrentDisplay({ isLoading, image }: CurrentDisplayProps
|
|||||||
</div>
|
</div>
|
||||||
)) || <h4 className="no-image">Try Making a new image!</h4>}
|
)) || <h4 className="no-image">Try Making a new image!</h4>}
|
||||||
|
|
||||||
<div></div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,22 +29,23 @@ export interface CompletedImagesType {
|
|||||||
info: ImageRequest;
|
info: ImageRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const idDelim = '_batch';
|
||||||
|
|
||||||
export default function DisplayPanel() {
|
export default function DisplayPanel() {
|
||||||
const dingRef = useRef<HTMLAudioElement>(null);
|
const dingRef = useRef<HTMLAudioElement>(null);
|
||||||
const isSoundEnabled = useImageCreate((state) => state.isSoundEnabled());
|
const isSoundEnabled = useImageCreate((state) => state.isSoundEnabled());
|
||||||
|
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const { id, options } = useImageQueue((state) => state.firstInQueue());
|
const { id, options } = useImageQueue((state) => state.firstInQueue());
|
||||||
const removeFirstInQueue = useImageQueue((state) => state.removeFirstInQueue);
|
const removeFirstInQueue = useImageQueue((state) => state.removeFirstInQueue);
|
||||||
|
|
||||||
const [currentImage, setCurrentImage] = useState<CompletedImagesType | null>(
|
const [currentImage, setCurrentImage] = useState<CompletedImagesType | null>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const [isEnabled, setIsEnabled] = useState(false);
|
const [isEnabled, setIsEnabled] = useState(false);
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
|
|
||||||
const { status, data } = useQuery(
|
const { status, data } = useQuery(
|
||||||
[MakeImageKey, id],
|
[MakeImageKey, id],
|
||||||
@ -54,11 +55,13 @@ export default function DisplayPanel() {
|
|||||||
// void 0 !== id,
|
// void 0 !== id,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// update the enabled state when the id changes
|
// update the enabled state when the id changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsEnabled(void 0 !== id)
|
setIsEnabled(void 0 !== id)
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
|
// helper for the loading state to be enabled aware
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isEnabled && status === "loading") {
|
if (isEnabled && status === "loading") {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@ -67,9 +70,8 @@ export default function DisplayPanel() {
|
|||||||
}
|
}
|
||||||
}, [isEnabled, status]);
|
}, [isEnabled, status]);
|
||||||
|
|
||||||
|
// this is where there loading actually happens
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("status", status);
|
|
||||||
// query is done
|
// query is done
|
||||||
if (status === "success") {
|
if (status === "success") {
|
||||||
// check to make sure that the image was created
|
// check to make sure that the image was created
|
||||||
@ -82,17 +84,17 @@ export default function DisplayPanel() {
|
|||||||
}
|
}
|
||||||
}, [status, data, removeFirstInQueue, dingRef, isSoundEnabled]);
|
}, [status, data, removeFirstInQueue, dingRef, isSoundEnabled]);
|
||||||
|
|
||||||
|
|
||||||
/* COMPLETED IMAGES */
|
/* COMPLETED IMAGES */
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [completedImages, setCompletedImages] = useState<CompletedImagesType[]>(
|
const [completedImages, setCompletedImages] = useState<CompletedImagesType[]>(
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const completedIds = useImageQueue((state) => state.completedImageIds);
|
const completedIds = useImageQueue((state) => state.completedImageIds);
|
||||||
|
const clearCachedIds = useImageQueue((state) => state.clearCachedIds);
|
||||||
|
|
||||||
// const init_image = useImageCreate((state) =>
|
// this is where we generate the list of completed images
|
||||||
// state.getValueForRequestKey("init_image")
|
|
||||||
// );
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const testReq = {} as ImageRequest;
|
const testReq = {} as ImageRequest;
|
||||||
const completedQueries = completedIds.map((id) => {
|
const completedQueries = completedIds.map((id) => {
|
||||||
@ -107,10 +109,10 @@ export default function DisplayPanel() {
|
|||||||
.map((query, index) => {
|
.map((query, index) => {
|
||||||
if (void 0 !== query) {
|
if (void 0 !== query) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return query.output.map((data) => {
|
return query.output.map((data, index) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return {
|
return {
|
||||||
id: `${completedIds[index]}-${data.seed}`,
|
id: `${completedIds[index]}${idDelim}-${data.seed}-${data.index}`,
|
||||||
data: data.data,
|
data: data.data,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
info: { ...query.request, seed: data.seed },
|
info: { ...query.request, seed: data.seed },
|
||||||
@ -123,9 +125,6 @@ export default function DisplayPanel() {
|
|||||||
.filter((item) => void 0 !== item) as CompletedImagesType[]; // remove undefined items
|
.filter((item) => void 0 !== item) as CompletedImagesType[]; // remove undefined items
|
||||||
|
|
||||||
setCompletedImages(temp);
|
setCompletedImages(temp);
|
||||||
|
|
||||||
console.log("temp", temp);
|
|
||||||
|
|
||||||
setCurrentImage(temp[0] || null);
|
setCurrentImage(temp[0] || null);
|
||||||
} else {
|
} else {
|
||||||
setCompletedImages([]);
|
setCompletedImages([]);
|
||||||
@ -133,9 +132,15 @@ export default function DisplayPanel() {
|
|||||||
}
|
}
|
||||||
}, [setCompletedImages, setCurrentImage, queryClient, completedIds]);
|
}, [setCompletedImages, setCurrentImage, queryClient, completedIds]);
|
||||||
|
|
||||||
useEffect(() => {
|
// this is how we remove them
|
||||||
console.log("completedImages", currentImage);
|
const removeImages = () => {
|
||||||
}, [currentImage]);
|
completedIds.forEach((id) => {
|
||||||
|
queryClient.removeQueries([MakeImageKey, id]);
|
||||||
|
});
|
||||||
|
clearCachedIds();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={displayPanel}>
|
<div className={displayPanel}>
|
||||||
@ -145,6 +150,7 @@ export default function DisplayPanel() {
|
|||||||
</div>
|
</div>
|
||||||
<div className={previousImages}>
|
<div className={previousImages}>
|
||||||
<CompletedImages
|
<CompletedImages
|
||||||
|
removeImages={removeImages}
|
||||||
images={completedImages}
|
images={completedImages}
|
||||||
setCurrentDisplay={setCurrentImage}
|
setCurrentDisplay={setCurrentImage}
|
||||||
></CompletedImages>
|
></CompletedImages>
|
||||||
|
@ -11,6 +11,7 @@ interface ImageQueueState {
|
|||||||
hasQueuedImages: () => boolean;
|
hasQueuedImages: () => boolean;
|
||||||
firstInQueue: () => ImageRequest | [];
|
firstInQueue: () => ImageRequest | [];
|
||||||
removeFirstInQueue: () => void;
|
removeFirstInQueue: () => void;
|
||||||
|
clearCachedIds: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// figure out why TS is complaining about this
|
// figure out why TS is complaining about this
|
||||||
@ -46,4 +47,12 @@ export const useImageQueue = create<ImageQueueState>((set, get) => ({
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
clearCachedIds: () => {
|
||||||
|
set(
|
||||||
|
produce((state) => {
|
||||||
|
state.completedImageIds = [];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
2
ui/frontend/dist/index.css
vendored
2
ui/frontend/dist/index.css
vendored
File diff suppressed because one or more lines are too long
32
ui/frontend/dist/index.js
vendored
32
ui/frontend/dist/index.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user