From 7d73a79671eaef3ffdce207942352981ea2b7816 Mon Sep 17 00:00:00 2001 From: jtydhr88 Date: Sun, 21 May 2023 22:13:40 -0400 Subject: [PATCH] add load existing images by extension on webui --- packages/stablestudio-plugin-webui/README.md | 7 ++- .../stablestudio-plugin-webui/src/index.ts | 57 +++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/packages/stablestudio-plugin-webui/README.md b/packages/stablestudio-plugin-webui/README.md index 6bcacca..d4b60a1 100644 --- a/packages/stablestudio-plugin-webui/README.md +++ b/packages/stablestudio-plugin-webui/README.md @@ -10,6 +10,7 @@ you can open http://127.0.0.1:7861/docs to double check. 4. once the server started, click settings to check this plugin loaded successfully or not. ![webui-plugin](docs/images/webui-plugin.png) ![overall](docs/images/overall.png) 5. click **Dream**, your webui server should start to process your request from StableStudio. +6. if you need to load existing from webui, you also need to install the extension [sd-webui-StableStudio](https://github.com/jtydhr88/sd-webui-StableStudio)) Still, currently this plugin is a basic implement for webui, and only support a few of features: - [x] txt2img @@ -21,11 +22,11 @@ Still, currently this plugin is a basic implement for webui, and only support a - [x] mask/inpaint/outpaint - [x] store settings - [x] webui status could replace images generated status +- [x] load existing images (need an extension on webui: [sd-webui-StableStudio](https://github.com/jtydhr88/sd-webui-StableStudio)) +- [x] Need to think about how to deal with extensions ecosystem in webui (made a start with [sd-webui-StableStudio](https://github.com/jtydhr88/sd-webui-StableStudio)) - [ ] upscale (working) -- [ ] Lora support -- [ ] load existing images +- [ ] Lora support - [ ] plugin could use path in settings along with a field for extra cli flags to launch webui on startup - [ ] some bugs fix - [ ] MacOS and Linux support (since I don’t have environment with MacOS/Linux, may need someone help with this) -- [ ] Need to think about how to deal with extensions ecosystem in webui - [ ] many other features from webui... \ No newline at end of file diff --git a/packages/stablestudio-plugin-webui/src/index.ts b/packages/stablestudio-plugin-webui/src/index.ts index ddc9977..cc11290 100644 --- a/packages/stablestudio-plugin-webui/src/index.ts +++ b/packages/stablestudio-plugin-webui/src/index.ts @@ -30,6 +30,7 @@ export const createPlugin = StableStudio.createPlugin<{ | "getStableDiffusionSamplers" | "getStableDiffusionDefaultCount" | "getStableDiffusionDefaultInput" + | "getStableDiffusionExistingImages" > => { if (webuiHostUrl === "") { webuiHostUrl = "http://127.0.0.1:7861"; @@ -292,6 +293,62 @@ export const createPlugin = StableStudio.createPlugin<{ return samplers; }, + getStableDiffusionExistingImages: async () => { + const existingImagesUrl = webuiHostUrl + '/StableStudio/get-generated-images'; + + const data = { + limit: 10 + } + + const existingImagesResponse = await fetch(existingImagesUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }); + + if (!existingImagesResponse.ok) { + console.warn("unable to get existing data from webui"); + } + + const responseData = await existingImagesResponse.json(); + + const images = []; + + for (let i = 0; i < responseData.length; i++) { + const blob = await base64ToBlob(responseData[i].content, 'image/jpeg'); + + const createdAt = new Date(); + + const stableDiffusionImage = { + id: responseData[i].image_name, + createdAt: createdAt, + blob: blob, + input: { + prompts: [], + style: "", + steps: -1, + seed: -1, + model: "", + width: responseData[i].width, + height: responseData[i].height + } + } + + images.push(stableDiffusionImage) + } + + const stableDiffusionImages = { + id: `${Math.random() * 10000000}`, + images: images + } + + console.log(responseData); + + return [stableDiffusionImages] + }, + imagesGeneratedSoFar: 0, settings: {