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
This commit is contained in:
error-usernotavailable 2024-10-16 22:23:31 -04:00 committed by GitHub
parent 725cfdebca
commit 2689025ec3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 56 additions and 31 deletions

View File

@ -219,6 +219,7 @@ const defaultSettings = {
// Automatic1111/Horde exclusives
restore_faces: false,
enable_hr: false,
aiFaceDetailer: false,
// Horde settings
horde: false,
@ -435,6 +436,7 @@ async function loadSettings() {
$('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize);
$('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces);
$('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr);
$('#sd_aiFaceDetailer').prop('checked', extension_settings.sd.aiFaceDetailer);
$('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode);
$('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning);
$('#sd_auto_url').val(extension_settings.sd.auto_url);
@ -853,6 +855,11 @@ function onSamplerChange() {
saveSettingsDebounced();
}
function onAiFaceDetailerChange() {
extension_settings.sd.aiFaceDetailer = $('#sd_aiFaceDetailer').prop('checked');
saveSettingsDebounced();
}
const resolutionOptions = {
sd_res_512x512: { width: 512, height: 512, name: '512x512 (1:1, icons, profile pictures)' },
sd_res_600x600: { width: 600, height: 600, name: '600x600 (1:1, icons, profile pictures)' },
@ -2920,42 +2927,59 @@ async function generateHordeImage(prompt, negativePrompt, signal) {
*/
async function generateAutoImage(prompt, negativePrompt, signal) {
const isValidVae = extension_settings.sd.vae && !['N/A', placeholderVae].includes(extension_settings.sd.vae);
let payload = {
...getSdRequestBody(),
prompt: prompt,
negative_prompt: negativePrompt,
sampler_name: extension_settings.sd.sampler,
scheduler: extension_settings.sd.scheduler,
steps: extension_settings.sd.steps,
cfg_scale: extension_settings.sd.scale,
width: extension_settings.sd.width,
height: extension_settings.sd.height,
restore_faces: !!extension_settings.sd.restore_faces,
enable_hr: !!extension_settings.sd.enable_hr,
hr_upscaler: extension_settings.sd.hr_upscaler,
hr_scale: extension_settings.sd.hr_scale,
denoising_strength: extension_settings.sd.denoising_strength,
hr_second_pass_steps: extension_settings.sd.hr_second_pass_steps,
seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined,
override_settings: {
CLIP_stop_at_last_layers: extension_settings.sd.clip_skip,
sd_vae: isValidVae ? extension_settings.sd.vae : undefined,
},
override_settings_restore_afterwards: true,
clip_skip: extension_settings.sd.clip_skip, // For SD.Next
save_images: true,
send_images: true,
do_not_save_grid: false,
do_not_save_samples: false,
};
// Conditionally add the ADetailer if aiFaceDetailer is enabled
console.log('extension_settings.sd.aiFaceDetailer:', extension_settings.sd.aiFaceDetailer);
if (extension_settings.sd.aiFaceDetailer) {
payload.alwayson_scripts = {
ADetailer: {
args: [
true, // ad_enable
true, // skip_img2img
{
"ad_model": "face_yolov8n.pt"
}
]
}
};
}
// Make the fetch call with the payload
const result = await fetch('/api/sd/generate', {
method: 'POST',
headers: getRequestHeaders(),
signal: signal,
body: JSON.stringify({
...getSdRequestBody(),
prompt: prompt,
negative_prompt: negativePrompt,
sampler_name: extension_settings.sd.sampler,
scheduler: extension_settings.sd.scheduler,
steps: extension_settings.sd.steps,
cfg_scale: extension_settings.sd.scale,
width: extension_settings.sd.width,
height: extension_settings.sd.height,
restore_faces: !!extension_settings.sd.restore_faces,
enable_hr: !!extension_settings.sd.enable_hr,
hr_upscaler: extension_settings.sd.hr_upscaler,
hr_scale: extension_settings.sd.hr_scale,
denoising_strength: extension_settings.sd.denoising_strength,
hr_second_pass_steps: extension_settings.sd.hr_second_pass_steps,
seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined,
// For AUTO1111
override_settings: {
CLIP_stop_at_last_layers: extension_settings.sd.clip_skip,
sd_vae: isValidVae ? extension_settings.sd.vae : undefined,
},
override_settings_restore_afterwards: true,
// For SD.Next
clip_skip: extension_settings.sd.clip_skip,
// Ensure generated img is saved to disk
save_images: true,
send_images: true,
do_not_save_grid: false,
do_not_save_samples: false,
}),
body: JSON.stringify(payload),
});
if (result.ok) {
const data = await result.json();
@ -4186,6 +4210,7 @@ jQuery(async () => {
$('#sd_horde_sanitize').on('input', onHordeSanitizeInput);
$('#sd_restore_faces').on('input', onRestoreFacesInput);
$('#sd_enable_hr').on('input', onHighResFixInput);
$('#sd_aiFaceDetailer').on('change', onAiFaceDetailerChange);
$('#sd_refine_mode').on('input', onRefineModeInput);
$('#sd_character_prompt').on('input', onCharacterPromptInput);
$('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput);