From 60652247586ab1790a484eb3e76805a21c57da28 Mon Sep 17 00:00:00 2001 From: xmodo <xmodo> Date: Wed, 15 Nov 2023 21:56:11 -0500 Subject: [PATCH] Add ADetailer --- js/003-data/gameVariableData.js | 1 + src/art/genAI/stableDiffusion.js | 20 ++++++++++- src/gui/options/options.js | 33 ++++++++++++++----- .../stableDiffusionInstallationGuide.js | 16 +++++++++ 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js index 9474af98943..9bd02d3faa2 100644 --- a/js/003-data/gameVariableData.js +++ b/js/003-data/gameVariableData.js @@ -192,6 +192,7 @@ App.Data.defaultGameStateVariables = { aiUpscaleScale: 1.75, aiUpscaler: "SwinIR_4x", aiWidth: 512, + aiAdetailerFace: false, showAgeDetail: 1, showAppraisal: 1, diff --git a/src/art/genAI/stableDiffusion.js b/src/art/genAI/stableDiffusion.js index 77e824c0c3f..c8ff0e7ccd4 100644 --- a/src/art/genAI/stableDiffusion.js +++ b/src/art/genAI/stableDiffusion.js @@ -17,6 +17,7 @@ App.Art.GenAI.StableDiffusionSettings = class { * @param {boolean} [restore_faces=true] Whether to use a model to restore faces or not * @param {string} [negative_prompt=""] * @param {string[]} [override_settings=["Discard penultimate sigma: True"]] + * @param {Object} [alwayson_scripts={}] Always on Scripts (e.g. ADetailer) */ /** @@ -40,6 +41,7 @@ App.Art.GenAI.StableDiffusionSettings = class { override_settings = { "always_discard_next_to_last_sigma": true, }, + alwayson_scripts = {} } = {}) { this.enable_hr = enable_hr; this.denoising_strength = denoising_strength; @@ -64,6 +66,7 @@ App.Art.GenAI.StableDiffusionSettings = class { this.restore_faces = restore_faces; this.override_strings = override_settings; this.override_settings_restore_afterwards = true; + this.alwayson_scripts = alwayson_scripts; } }; @@ -254,6 +257,20 @@ App.Art.GenAI.StableDiffusionClient = class { */ buildStableDiffusionSettings(slave, steps) { const prompt = buildPrompt(slave); + + // TODO: Add more config options to ADetailer, and add ReActor + const alwaysOnScripts = {}; + if (V.aiAdetailerFace) { + // API Docs: https://github.com/Bing-su/adetailer/wiki/API + alwaysOnScripts.ADetailer = { + "args": [ + { + "ad_model": "face_yolov8s.pt" + } + ] + }; + } + const settings = new App.Art.GenAI.StableDiffusionSettings({ cfg_scale: V.aiCfgScale, enable_hr: V.aiUpscale, @@ -266,7 +283,8 @@ App.Art.GenAI.StableDiffusionClient = class { seed: slave.natural.artSeed, steps: steps, width: V.aiWidth, - restore_faces: V.aiRestoreFaces + restore_faces: V.aiRestoreFaces, + alwayson_scripts: alwaysOnScripts }); return settings; } diff --git a/src/gui/options/options.js b/src/gui/options/options.js index 2aa61f23bd8..0489744d5b9 100644 --- a/src/gui/options/options.js +++ b/src/gui/options/options.js @@ -1293,29 +1293,43 @@ App.UI.artOptions = function() { .addValue("Enabled", true).on().addValue("Disabled", false).off() .addComment("Generate images for new slaves on the fly. If disabled, you will need to manually click to generate each slave's image."); if (V.aiAutoGen) { - if (V.aiAutoGenFrequency < 1) V.aiAutoGenFrequency = 1; + if (V.aiAutoGenFrequency < 1) { + V.aiAutoGenFrequency = 1; + } V.aiAutoGenFrequency = Math.round(V.aiAutoGenFrequency); options.addOption("Regeneration Frequency", "aiAutoGenFrequency").showTextBox() - .addComment("How often (in weeks) regenerate slave images. Slaves will render when 'Weeks Owned' is divisible by this number."); + .addComment("How often (in weeks) regenerate slave images. Slaves will render when 'Weeks Owned' is divisible by this number."); } options.addOption("Sampling Method", "aiSamplingMethod").showTextBox() .addComment(`The sampling method used by AI. You can query ${V.aiApiUrl}/sdapi/v1/samplers to see the list of available samplers.`); - if (V.aiCfgScale < 1) V.aiCfgScale = 1; + if (V.aiCfgScale < 1) { + V.aiCfgScale = 1; + } options.addOption("CFG Scale", "aiCfgScale").showTextBox() .addComment("The higher this number, the more the prompt influences the image. Generally between 5 to 12."); - if (V.aiTimeoutPerStep < 0.01) V.aiTimeoutPerStep = 0.01; + if (V.aiTimeoutPerStep < 0.01) { + V.aiTimeoutPerStep = 0.01; + } options.addOption("Seconds per Step", "aiTimeoutPerStep").showTextBox() .addComment("The maximum number of Seconds (per Step) your system takes to render an image. This time is from the time the request is sent to the time it is saved divided by the number of Sampling Steps. Please set this at as small a value as reasonable to avoid the game from waiting longer than you are for images to generate."); - if (V.aiSamplingSteps < 2) V.aiSamplingSteps = 2; + if (V.aiSamplingSteps < 2) { + V.aiSamplingSteps = 2; + } options.addOption("Sampling Steps", "aiSamplingSteps").showTextBox() .addComment("The number of steps used when generating the image. More steps might reduce artifacts but increases generation time. Generally between 20 to 50, but may be as high as 500 if you don't mind long queues in the background."); - if (V.aiSamplingStepsEvent < 2) V.aiSamplingStepsEvent = 2; + if (V.aiSamplingStepsEvent < 2) { + V.aiSamplingStepsEvent = 2; + } options.addOption("Event Sampling Steps", "aiSamplingStepsEvent").showTextBox() .addComment("The number of steps used when generating an image during events. Generally between 20 to 50 to maintain a reasonable speed."); - if (V.aiHeight < 10) V.aiHeight = 10; + if (V.aiHeight < 10) { + V.aiHeight = 10; + } options.addOption("Height", "aiHeight").showTextBox() .addComment("The height of the image."); - if (V.aiWidth < 10) V.aiWidth = 10; + if (V.aiWidth < 10) { + V.aiWidth = 10; + } options.addOption("Width", "aiWidth").showTextBox() .addComment("The width of the image."); options.addOption("Restore Faces", "aiRestoreFaces") @@ -1324,6 +1338,9 @@ App.UI.artOptions = function() { options.addOption("Upscaling/highres fix", "aiUpscale") .addValue("Enabled", true).on().addValue("Disabled", false).off() .addComment("Use AI upscaling to produce higher-resolution images. Significantly increases both time to generate and image quality."); + options.addOption("ADetailer restore face", "aiAdetailerFace") + .addValue("Enabled", true).on().addValue("Disabled", false).off() + .addComment("Use AI to clean up the face. Extremely small impact to generation time, moderate impact to image quality. Allows you to use a higher CFG."); if (V.aiUpscale) { options.addOption("Upscaling size", "aiUpscaleScale").showTextBox() .addComment("Scales the dimensions of the image by this factor. Defaults to 1.7."); diff --git a/src/gui/options/stableDiffusionInstallationGuide.js b/src/gui/options/stableDiffusionInstallationGuide.js index 1998ead9cfb..b2fc426717a 100644 --- a/src/gui/options/stableDiffusionInstallationGuide.js +++ b/src/gui/options/stableDiffusionInstallationGuide.js @@ -48,6 +48,22 @@ Once it's running, open your browser and go to <code>localhost:7860</code>. The <h2>7. Check it works</h2> <p>At this point, if you go to a slave's detail page their image should load after a short (<30 seconds) delay. If it doesn't seem to be working, have a look at the terminal window running Automatic1111's Stable Diffusion WebUI to see if there are any errors.</p> <p>The request will time out if the image can't be generated fast enough; if this is the case for you, try to find a guide to optimizing Stable Diffusion for your particular hardware setup, or disable the "Upscaling/highres fix" option.</p> + +<h2>(Optional) 8. Optimise Your Install</h2> +<h3>ADetailer</h3> +<p><a href="https://github.com/Bing-su/adetailer">ADetailer</a> is a performant way to refine your images (taking less than 10ms on some systems)</p> +<p>Follow the instructions on the GitHub page to install.</p> +<p>Remember to restart Stable Diffusion!</p> + +<h3>Webp Images</h3> +<p>WEBP images (~30 kB) take up much less space compared to JPEG (60-200 kB) or PNG (1-2.5 MB). This is one way you can make images quicker to display, and have less saved on your hard disk as well.</p> +<ol> + <li>In the Auto1111 WebUI, in the top toolbar and click "Settings"</li> + <li>Then, click on the top option of the sidebar (Saving images/grids). You might be there by default.</li> + <li>In the first text field, "File format for images", enter "webp" without quotes.</li> + <li>Click the "Apply settings" button at the top, then the "Reload UI" button.</li> +</ol> + `; const loraHTML = ` -- GitLab