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:
parent
725cfdebca
commit
2689025ec3
|
@ -219,6 +219,7 @@ const defaultSettings = {
|
||||||
// Automatic1111/Horde exclusives
|
// Automatic1111/Horde exclusives
|
||||||
restore_faces: false,
|
restore_faces: false,
|
||||||
enable_hr: false,
|
enable_hr: false,
|
||||||
|
aiFaceDetailer: false,
|
||||||
|
|
||||||
// Horde settings
|
// Horde settings
|
||||||
horde: false,
|
horde: false,
|
||||||
|
@ -435,6 +436,7 @@ async function loadSettings() {
|
||||||
$('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize);
|
$('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize);
|
||||||
$('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces);
|
$('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces);
|
||||||
$('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr);
|
$('#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_refine_mode').prop('checked', extension_settings.sd.refine_mode);
|
||||||
$('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning);
|
$('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning);
|
||||||
$('#sd_auto_url').val(extension_settings.sd.auto_url);
|
$('#sd_auto_url').val(extension_settings.sd.auto_url);
|
||||||
|
@ -853,6 +855,11 @@ function onSamplerChange() {
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onAiFaceDetailerChange() {
|
||||||
|
extension_settings.sd.aiFaceDetailer = $('#sd_aiFaceDetailer').prop('checked');
|
||||||
|
saveSettingsDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
const resolutionOptions = {
|
const resolutionOptions = {
|
||||||
sd_res_512x512: { width: 512, height: 512, name: '512x512 (1:1, icons, profile pictures)' },
|
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)' },
|
sd_res_600x600: { width: 600, height: 600, name: '600x600 (1:1, icons, profile pictures)' },
|
||||||
|
@ -2920,11 +2927,7 @@ async function generateHordeImage(prompt, negativePrompt, signal) {
|
||||||
*/
|
*/
|
||||||
async function generateAutoImage(prompt, negativePrompt, signal) {
|
async function generateAutoImage(prompt, negativePrompt, signal) {
|
||||||
const isValidVae = extension_settings.sd.vae && !['N/A', placeholderVae].includes(extension_settings.sd.vae);
|
const isValidVae = extension_settings.sd.vae && !['N/A', placeholderVae].includes(extension_settings.sd.vae);
|
||||||
const result = await fetch('/api/sd/generate', {
|
let payload = {
|
||||||
method: 'POST',
|
|
||||||
headers: getRequestHeaders(),
|
|
||||||
signal: signal,
|
|
||||||
body: JSON.stringify({
|
|
||||||
...getSdRequestBody(),
|
...getSdRequestBody(),
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
negative_prompt: negativePrompt,
|
negative_prompt: negativePrompt,
|
||||||
|
@ -2941,22 +2944,43 @@ async function generateAutoImage(prompt, negativePrompt, signal) {
|
||||||
denoising_strength: extension_settings.sd.denoising_strength,
|
denoising_strength: extension_settings.sd.denoising_strength,
|
||||||
hr_second_pass_steps: extension_settings.sd.hr_second_pass_steps,
|
hr_second_pass_steps: extension_settings.sd.hr_second_pass_steps,
|
||||||
seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined,
|
seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined,
|
||||||
// For AUTO1111
|
|
||||||
override_settings: {
|
override_settings: {
|
||||||
CLIP_stop_at_last_layers: extension_settings.sd.clip_skip,
|
CLIP_stop_at_last_layers: extension_settings.sd.clip_skip,
|
||||||
sd_vae: isValidVae ? extension_settings.sd.vae : undefined,
|
sd_vae: isValidVae ? extension_settings.sd.vae : undefined,
|
||||||
},
|
},
|
||||||
override_settings_restore_afterwards: true,
|
override_settings_restore_afterwards: true,
|
||||||
// For SD.Next
|
clip_skip: extension_settings.sd.clip_skip, // For SD.Next
|
||||||
clip_skip: extension_settings.sd.clip_skip,
|
|
||||||
// Ensure generated img is saved to disk
|
|
||||||
save_images: true,
|
save_images: true,
|
||||||
send_images: true,
|
send_images: true,
|
||||||
do_not_save_grid: false,
|
do_not_save_grid: false,
|
||||||
do_not_save_samples: 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(payload),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
const data = await result.json();
|
const data = await result.json();
|
||||||
return { format: 'png', data: data.images[0] };
|
return { format: 'png', data: data.images[0] };
|
||||||
|
@ -4186,6 +4210,7 @@ jQuery(async () => {
|
||||||
$('#sd_horde_sanitize').on('input', onHordeSanitizeInput);
|
$('#sd_horde_sanitize').on('input', onHordeSanitizeInput);
|
||||||
$('#sd_restore_faces').on('input', onRestoreFacesInput);
|
$('#sd_restore_faces').on('input', onRestoreFacesInput);
|
||||||
$('#sd_enable_hr').on('input', onHighResFixInput);
|
$('#sd_enable_hr').on('input', onHighResFixInput);
|
||||||
|
$('#sd_aiFaceDetailer').on('change', onAiFaceDetailerChange);
|
||||||
$('#sd_refine_mode').on('input', onRefineModeInput);
|
$('#sd_refine_mode').on('input', onRefineModeInput);
|
||||||
$('#sd_character_prompt').on('input', onCharacterPromptInput);
|
$('#sd_character_prompt').on('input', onCharacterPromptInput);
|
||||||
$('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput);
|
$('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput);
|
||||||
|
|
Loading…
Reference in New Issue