StableStudio
StableStudio copied to clipboard
Support streaming images via AsyncGenerator in `createStableDiffusionImages`
It would be great if the interface would support streaming images using AsyncGenerator
.
E.g.
createStableDiffusionImages: async function* (options) {
const image = await fetch(`${window.location.origin}/DummyImage.png`);
const blob = await image.blob();
const createdAt = new Date();
for (let i = 0; i < (options?.count || 4); i++) {
yield {
id: `${Math.random() * 10000000}`,
createdAt,
blob,
};
set(({ imagesGeneratedSoFar }) => ({
imagesGeneratedSoFar: imagesGeneratedSoFar + 1,
}));
await new Promise((resolve) => setTimeout(resolve, 1000));
}
},
The type could look something like:
createStableDiffusionImages?: (options?: {
/** The `StableDiffusionInput` you've been asked to generate, if empty, you could still return a random image */
input?: StableDiffusionInput;
/** Determines how many images will be created using the given `StableDiffusionInput` */
count?: number;
}) =>
| MaybePromise<StableDiffusionImages | undefined>
| AsyncGenerator<StableDiffusionImage>;
to support both flows.
What do you think?