Update index.js to use ADetailer in Auto1111/Forge/Vlad added events, listener, and function for ADetailer/aiFaceDetailer. Rewrote function generateAutoImage to allow for tacking on of alwayson_scripts (maybe redo for a textbox/json later for other Auto1111 extensions?) paired with settings.html edits
Signed| @@ -219,6 +219,7 @@ const defaultSettings = { | |||
| 219 | // Automatic1111/Horde exclusives | 219 | // Automatic1111/Horde exclusives |
| 220 | restore_faces: false, | 220 | restore_faces: false, |
| 221 | enable_hr: false, | 221 | enable_hr: false, |
| 222 | aiFaceDetailer: false, | ||
| 222 | 223 | ||
| 223 | // Horde settings | 224 | // Horde settings |
| 224 | horde: false, | 225 | horde: false, |
| @@ -435,6 +436,7 @@ async function loadSettings() { | |||
| 435 | $('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize); | 436 | $('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize); |
| 436 | $('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces); | 437 | $('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces); |
| 437 | $('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr); | 438 | $('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr); |
| 439 | $('#sd_aiFaceDetailer').prop('checked', extension_settings.sd.aiFaceDetailer); | ||
| 438 | $('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode); | 440 | $('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode); |
| 439 | $('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning); | 441 | $('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning); |
| 440 | $('#sd_auto_url').val(extension_settings.sd.auto_url); | 442 | $('#sd_auto_url').val(extension_settings.sd.auto_url); |
| @@ -853,6 +855,11 @@ function onSamplerChange() { | |||
| 853 | saveSettingsDebounced(); | 855 | saveSettingsDebounced(); |
| 854 | } | 856 | } |
| 855 | 857 | ||
| 858 | function onAiFaceDetailerChange() { | ||
| 859 | extension_settings.sd.aiFaceDetailer = $('#sd_aiFaceDetailer').prop('checked'); | ||
| 860 | saveSettingsDebounced(); | ||
| 861 | } | ||
| 862 | |||
| 856 | const resolutionOptions = { | 863 | const resolutionOptions = { |
| 857 | sd_res_512x512: { width: 512, height: 512, name: '512x512 (1:1, icons, profile pictures)' }, | 864 | sd_res_512x512: { width: 512, height: 512, name: '512x512 (1:1, icons, profile pictures)' }, |
| 858 | sd_res_600x600: { width: 600, height: 600, name: '600x600 (1:1, icons, profile pictures)' }, | 865 | sd_res_600x600: { width: 600, height: 600, name: '600x600 (1:1, icons, profile pictures)' }, |
| @@ -2920,11 +2927,7 @@ async function generateHordeImage(prompt, negativePrompt, signal) { | |||
| 2920 | */ | 2927 | */ |
| 2921 | async function generateAutoImage(prompt, negativePrompt, signal) { | 2928 | async function generateAutoImage(prompt, negativePrompt, signal) { |
| 2922 | const isValidVae = extension_settings.sd.vae && !['N/A', placeholderVae].includes(extension_settings.sd.vae); | 2929 | const isValidVae = extension_settings.sd.vae && !['N/A', placeholderVae].includes(extension_settings.sd.vae); |
| 2923 | const result = await fetch('/api/sd/generate', { | 2930 | let payload = { |
| 2924 | method: 'POST', | ||
| 2925 | headers: getRequestHeaders(), | ||
| 2926 | signal: signal, | ||
| 2927 | body: JSON.stringify({ | ||
| 2928 | ...getSdRequestBody(), | 2931 | ...getSdRequestBody(), |
| 2929 | prompt: prompt, | 2932 | prompt: prompt, |
| 2930 | negative_prompt: negativePrompt, | 2933 | negative_prompt: negativePrompt, |
| @@ -2941,22 +2944,43 @@ async function generateAutoImage(prompt, negativePrompt, signal) { | |||
| 2941 | denoising_strength: extension_settings.sd.denoising_strength, | 2944 | denoising_strength: extension_settings.sd.denoising_strength, |
| 2942 | hr_second_pass_steps: extension_settings.sd.hr_second_pass_steps, | 2945 | hr_second_pass_steps: extension_settings.sd.hr_second_pass_steps, |
| 2943 | seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined, | 2946 | seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined, |
| 2944 | // For AUTO1111 | ||
| 2945 | override_settings: { | 2947 | override_settings: { |
| 2946 | CLIP_stop_at_last_layers: extension_settings.sd.clip_skip, | 2948 | CLIP_stop_at_last_layers: extension_settings.sd.clip_skip, |
| 2947 | sd_vae: isValidVae ? extension_settings.sd.vae : undefined, | 2949 | sd_vae: isValidVae ? extension_settings.sd.vae : undefined, |
| 2948 | }, | 2950 | }, |
| 2949 | override_settings_restore_afterwards: true, | 2951 | override_settings_restore_afterwards: true, |
| 2950 | // For SD.Next | 2952 | clip_skip: extension_settings.sd.clip_skip, // For SD.Next |
| 2951 | clip_skip: extension_settings.sd.clip_skip, | ||
| 2952 | // Ensure generated img is saved to disk | ||
| 2953 | save_images: true, | 2953 | save_images: true, |
| 2954 | send_images: true, | 2954 | send_images: true, |
| 2955 | do_not_save_grid: false, | 2955 | do_not_save_grid: false, |
| 2956 | do_not_save_samples: false, | 2956 | do_not_save_samples: false, |
| 2957 | }), | 2957 | }; |
| 2958 | // Conditionally add the ADetailer if aiFaceDetailer is enabled | ||
| 2959 | console.log('extension_settings.sd.aiFaceDetailer:', extension_settings.sd.aiFaceDetailer); | ||
| 2960 | if (extension_settings.sd.aiFaceDetailer) { | ||
| 2961 | payload.alwayson_scripts = { | ||
| 2962 | ADetailer: { | ||
| 2963 | args: [ | ||
| 2964 | true, // ad_enable | ||
| 2965 | true, // skip_img2img | ||
| 2966 | { | ||
| 2967 | "ad_model": "face_yolov8n.pt" | ||
| 2968 | } | ||
| 2969 | ] | ||
| 2970 | } | ||
| 2971 | }; | ||
| 2972 | } | ||
| 2973 | |||
| 2974 | // Make the fetch call with the payload | ||
| 2975 | const result = await fetch('/api/sd/generate', { | ||
| 2976 | method: 'POST', | ||
| 2977 | headers: getRequestHeaders(), | ||
| 2978 | signal: signal, | ||
| 2979 | body: JSON.stringify(payload), | ||
| 2958 | }); | 2980 | }); |
| 2959 | 2981 | ||
| 2982 | |||
| 2983 | |||
| 2960 | if (result.ok) { | 2984 | if (result.ok) { |
| 2961 | const data = await result.json(); | 2985 | const data = await result.json(); |
| 2962 | return { format: 'png', data: data.images[0] }; | 2986 | return { format: 'png', data: data.images[0] }; |
| @@ -4186,6 +4210,7 @@ jQuery(async () => { | |||
| 4186 | $('#sd_horde_sanitize').on('input', onHordeSanitizeInput); | 4210 | $('#sd_horde_sanitize').on('input', onHordeSanitizeInput); |
| 4187 | $('#sd_restore_faces').on('input', onRestoreFacesInput); | 4211 | $('#sd_restore_faces').on('input', onRestoreFacesInput); |
| 4188 | $('#sd_enable_hr').on('input', onHighResFixInput); | 4212 | $('#sd_enable_hr').on('input', onHighResFixInput); |
| 4213 | $('#sd_aiFaceDetailer').on('change', onAiFaceDetailerChange); | ||
| 4189 | $('#sd_refine_mode').on('input', onRefineModeInput); | 4214 | $('#sd_refine_mode').on('input', onRefineModeInput); |
| 4190 | $('#sd_character_prompt').on('input', onCharacterPromptInput); | 4215 | $('#sd_character_prompt').on('input', onCharacterPromptInput); |
| 4191 | $('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput); | 4216 | $('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput); |