mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Add SMEA/DYN controls for NAI Diffusion
This commit is contained in:
		| @@ -237,6 +237,8 @@ const defaultSettings = { | |||||||
|     novel_upscale_ratio_step: 0.1, |     novel_upscale_ratio_step: 0.1, | ||||||
|     novel_upscale_ratio: 1.0, |     novel_upscale_ratio: 1.0, | ||||||
|     novel_anlas_guard: false, |     novel_anlas_guard: false, | ||||||
|  |     novel_sm: false, | ||||||
|  |     novel_sm_dyn: false, | ||||||
|  |  | ||||||
|     // OpenAI settings |     // OpenAI settings | ||||||
|     openai_style: 'vivid', |     openai_style: 'vivid', | ||||||
| @@ -372,6 +374,9 @@ async function loadSettings() { | |||||||
|     $('#sd_hr_second_pass_steps').val(extension_settings.sd.hr_second_pass_steps).trigger('input'); |     $('#sd_hr_second_pass_steps').val(extension_settings.sd.hr_second_pass_steps).trigger('input'); | ||||||
|     $('#sd_novel_upscale_ratio').val(extension_settings.sd.novel_upscale_ratio).trigger('input'); |     $('#sd_novel_upscale_ratio').val(extension_settings.sd.novel_upscale_ratio).trigger('input'); | ||||||
|     $('#sd_novel_anlas_guard').prop('checked', extension_settings.sd.novel_anlas_guard); |     $('#sd_novel_anlas_guard').prop('checked', extension_settings.sd.novel_anlas_guard); | ||||||
|  |     $('#sd_novel_sm').prop('checked', extension_settings.sd.novel_sm); | ||||||
|  |     $('#sd_novel_sm_dyn').prop('checked', extension_settings.sd.novel_sm_dyn); | ||||||
|  |     $('#sd_novel_sm_dyn').prop('disabled', !extension_settings.sd.novel_sm); | ||||||
|     $('#sd_horde').prop('checked', extension_settings.sd.horde); |     $('#sd_horde').prop('checked', extension_settings.sd.horde); | ||||||
|     $('#sd_horde_nsfw').prop('checked', extension_settings.sd.horde_nsfw); |     $('#sd_horde_nsfw').prop('checked', extension_settings.sd.horde_nsfw); | ||||||
|     $('#sd_horde_karras').prop('checked', extension_settings.sd.horde_karras); |     $('#sd_horde_karras').prop('checked', extension_settings.sd.horde_karras); | ||||||
| @@ -799,6 +804,22 @@ function onNovelAnlasGuardInput() { | |||||||
|     saveSettingsDebounced(); |     saveSettingsDebounced(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function onNovelSmInput() { | ||||||
|  |     extension_settings.sd.novel_sm = !!$('#sd_novel_sm').prop('checked'); | ||||||
|  |     saveSettingsDebounced(); | ||||||
|  |  | ||||||
|  |     if (!extension_settings.sd.novel_sm) { | ||||||
|  |         $('#sd_novel_sm_dyn').prop('checked', false).prop('disabled', true).trigger('input'); | ||||||
|  |     } else { | ||||||
|  |         $('#sd_novel_sm_dyn').prop('disabled', false); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function onNovelSmDynInput() { | ||||||
|  |     extension_settings.sd.novel_sm_dyn = !!$('#sd_novel_sm_dyn').prop('checked'); | ||||||
|  |     saveSettingsDebounced(); | ||||||
|  | } | ||||||
|  |  | ||||||
| function onHordeNsfwInput() { | function onHordeNsfwInput() { | ||||||
|     extension_settings.sd.horde_nsfw = !!$(this).prop('checked'); |     extension_settings.sd.horde_nsfw = !!$(this).prop('checked'); | ||||||
|     saveSettingsDebounced(); |     saveSettingsDebounced(); | ||||||
| @@ -2165,7 +2186,7 @@ async function generateAutoImage(prompt, negativePrompt) { | |||||||
|  * @returns {Promise<{format: string, data: string}>} - A promise that resolves when the image generation and processing are complete. |  * @returns {Promise<{format: string, data: string}>} - A promise that resolves when the image generation and processing are complete. | ||||||
|  */ |  */ | ||||||
| async function generateNovelImage(prompt, negativePrompt) { | async function generateNovelImage(prompt, negativePrompt) { | ||||||
|     const { steps, width, height } = getNovelParams(); |     const { steps, width, height, sm, sm_dyn } = getNovelParams(); | ||||||
|  |  | ||||||
|     const result = await fetch('/api/novelai/generate-image', { |     const result = await fetch('/api/novelai/generate-image', { | ||||||
|         method: 'POST', |         method: 'POST', | ||||||
| @@ -2180,6 +2201,8 @@ async function generateNovelImage(prompt, negativePrompt) { | |||||||
|             height: height, |             height: height, | ||||||
|             negative_prompt: negativePrompt, |             negative_prompt: negativePrompt, | ||||||
|             upscale_ratio: extension_settings.sd.novel_upscale_ratio, |             upscale_ratio: extension_settings.sd.novel_upscale_ratio, | ||||||
|  |             sm: sm, | ||||||
|  |             sm_dyn: sm_dyn, | ||||||
|         }), |         }), | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
| @@ -2194,16 +2217,23 @@ async function generateNovelImage(prompt, negativePrompt) { | |||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Adjusts extension parameters for NovelAI. Applies Anlas guard if needed. |  * Adjusts extension parameters for NovelAI. Applies Anlas guard if needed. | ||||||
|  * @returns {{steps: number, width: number, height: number}} - A tuple of parameters for NovelAI API. |  * @returns {{steps: number, width: number, height: number, sm: boolean, sm_dyn: boolean}} - A tuple of parameters for NovelAI API. | ||||||
|  */ |  */ | ||||||
| function getNovelParams() { | function getNovelParams() { | ||||||
|     let steps = extension_settings.sd.steps; |     let steps = extension_settings.sd.steps; | ||||||
|     let width = extension_settings.sd.width; |     let width = extension_settings.sd.width; | ||||||
|     let height = extension_settings.sd.height; |     let height = extension_settings.sd.height; | ||||||
|  |     let sm = extension_settings.sd.novel_sm; | ||||||
|  |     let sm_dyn = extension_settings.sd.novel_sm_dyn; | ||||||
|  |  | ||||||
|  |     if (extension_settings.sd.sampler === 'ddim') { | ||||||
|  |         sm = false; | ||||||
|  |         sm_dyn = false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // Don't apply Anlas guard if it's disabled. |     // Don't apply Anlas guard if it's disabled. | ||||||
|     if (!extension_settings.sd.novel_anlas_guard) { |     if (!extension_settings.sd.novel_anlas_guard) { | ||||||
|         return { steps, width, height }; |         return { steps, width, height, sm, sm_dyn }; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const MAX_STEPS = 28; |     const MAX_STEPS = 28; | ||||||
| @@ -2244,7 +2274,7 @@ function getNovelParams() { | |||||||
|         steps = MAX_STEPS; |         steps = MAX_STEPS; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return { steps, width, height }; |     return { steps, width, height, sm, sm_dyn }; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function generateOpenAiImage(prompt) { | async function generateOpenAiImage(prompt) { | ||||||
| @@ -2725,6 +2755,8 @@ jQuery(async () => { | |||||||
|     $('#sd_novel_upscale_ratio').on('input', onNovelUpscaleRatioInput); |     $('#sd_novel_upscale_ratio').on('input', onNovelUpscaleRatioInput); | ||||||
|     $('#sd_novel_anlas_guard').on('input', onNovelAnlasGuardInput); |     $('#sd_novel_anlas_guard').on('input', onNovelAnlasGuardInput); | ||||||
|     $('#sd_novel_view_anlas').on('click', onViewAnlasClick); |     $('#sd_novel_view_anlas').on('click', onViewAnlasClick); | ||||||
|  |     $('#sd_novel_sm').on('input', onNovelSmInput); | ||||||
|  |     $('#sd_novel_sm_dyn').on('input', onNovelSmDynInput);; | ||||||
|     $('#sd_comfy_validate').on('click', validateComfyUrl); |     $('#sd_comfy_validate').on('click', validateComfyUrl); | ||||||
|     $('#sd_comfy_url').on('input', onComfyUrlInput); |     $('#sd_comfy_url').on('input', onComfyUrlInput); | ||||||
|     $('#sd_comfy_workflow').on('change', onComfyWorkflowChange); |     $('#sd_comfy_workflow').on('change', onComfyWorkflowChange); | ||||||
|   | |||||||
| @@ -85,15 +85,9 @@ | |||||||
|                         Sanitize prompts (recommended) |                         Sanitize prompts (recommended) | ||||||
|                     </span> |                     </span> | ||||||
|                 </label> |                 </label> | ||||||
|                 <label for="sd_horde_karras" class="checkbox_label"> |  | ||||||
|                     <input id="sd_horde_karras" type="checkbox" /> |  | ||||||
|                     <span data-i18n="Karras (not all samplers supported)"> |  | ||||||
|                         Karras (not all samplers supported) |  | ||||||
|                     </span> |  | ||||||
|                 </label> |  | ||||||
|             </div> |             </div> | ||||||
|             <div data-sd-source="novel"> |             <div data-sd-source="novel"> | ||||||
|                 <div class="flex-container"> |                 <div class="flex-container flexFlowColumn"> | ||||||
|                     <label for="sd_novel_anlas_guard" class="checkbox_label flex1" title="Automatically adjust generation parameters to ensure free image generations."> |                     <label for="sd_novel_anlas_guard" class="checkbox_label flex1" title="Automatically adjust generation parameters to ensure free image generations."> | ||||||
|                         <input id="sd_novel_anlas_guard" type="checkbox" /> |                         <input id="sd_novel_anlas_guard" type="checkbox" /> | ||||||
|                         <span data-i18n="Avoid spending Anlas"> |                         <span data-i18n="Avoid spending Anlas"> | ||||||
| @@ -160,6 +154,26 @@ | |||||||
|             <select id="sd_model"></select> |             <select id="sd_model"></select> | ||||||
|             <label for="sd_sampler">Sampling method</label> |             <label for="sd_sampler">Sampling method</label> | ||||||
|             <select id="sd_sampler"></select> |             <select id="sd_sampler"></select> | ||||||
|  |             <label data-sd-source="horde" for="sd_horde_karras" class="checkbox_label"> | ||||||
|  |                 <input id="sd_horde_karras" type="checkbox" /> | ||||||
|  |                 <span data-i18n="Karras (not all samplers supported)"> | ||||||
|  |                     Karras (not all samplers supported) | ||||||
|  |                 </span> | ||||||
|  |             </label> | ||||||
|  |             <div data-sd-source="novel" class="flex-container"> | ||||||
|  |                 <label class="flex1 checkbox_label" title="SMEA versions of samplers are modified to perform better at high resolution."> | ||||||
|  |                     <input id="sd_novel_sm" type="checkbox" /> | ||||||
|  |                     <span data-i18n="SMEA"> | ||||||
|  |                         SMEA | ||||||
|  |                     </span> | ||||||
|  |                 </label> | ||||||
|  |                 <label class="flex1 checkbox_label" title="DYN variants of SMEA samplers often lead to more varied output, but may fail at very high resolutions."> | ||||||
|  |                     <input id="sd_novel_sm_dyn" type="checkbox" /> | ||||||
|  |                     <span data-i18n="DYN"> | ||||||
|  |                         DYN | ||||||
|  |                     </span> | ||||||
|  |                 </label> | ||||||
|  |             </div> | ||||||
|             <label for="sd_resolution">Resolution</label> |             <label for="sd_resolution">Resolution</label> | ||||||
|             <select id="sd_resolution"><!-- Populated in JS --></select> |             <select id="sd_resolution"><!-- Populated in JS --></select> | ||||||
|             <div data-sd-source="comfy"> |             <div data-sd-source="comfy"> | ||||||
|   | |||||||
| @@ -265,8 +265,8 @@ router.post('/generate-image', jsonParser, async (request, response) => { | |||||||
|                     controlnet_strength: 1, |                     controlnet_strength: 1, | ||||||
|                     dynamic_thresholding: false, |                     dynamic_thresholding: false, | ||||||
|                     legacy: false, |                     legacy: false, | ||||||
|                     sm: false, |                     sm: request.body.sm ?? false, | ||||||
|                     sm_dyn: false, |                     sm_dyn: request.body.sm_dyn ?? false, | ||||||
|                     uncond_scale: 1, |                     uncond_scale: 1, | ||||||
|                 }, |                 }, | ||||||
|             }), |             }), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user