#612 SD manual prompt refine mode

This commit is contained in:
Cohee
2023-07-10 23:07:53 +03:00
parent 66a50f6afb
commit 5c6c7fd3ca
5 changed files with 33 additions and 7 deletions

View File

@@ -131,6 +131,9 @@ const defaultSettings = {
horde: false,
horde_nsfw: false,
horde_karras: true,
// Refine mode
refine_mode: false,
}
async function loadSettings() {
@@ -149,10 +152,16 @@ async function loadSettings() {
$('#sd_horde_karras').prop('checked', extension_settings.sd.horde_karras);
$('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces);
$('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr);
$('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode);
await Promise.all([loadSamplers(), loadModels()]);
}
function onRefineModeInput() {
extension_settings.sd.refine_mode = !!$('#sd_refine_mode').prop('checked');
saveSettingsDebounced();
}
function onScaleInput() {
extension_settings.sd.scale = Number($('#sd_scale').val());
$('#sd_scale_value').text(extension_settings.sd.scale.toFixed(1));
@@ -470,7 +479,7 @@ async function getPrompt(generationType, message, trigger, quiet_prompt) {
}
async function generatePrompt(quiet_prompt) {
return processReply(await new Promise(
let reply = processReply(await new Promise(
async function promptPromise(resolve, reject) {
try {
await getContext().generate('quiet', { resolve, reject, quiet_prompt, force_name2: true, });
@@ -479,6 +488,18 @@ async function generatePrompt(quiet_prompt) {
reject();
}
}));
if (extension_settings.sd.refine_mode) {
const refinedPrompt = await callPopup('<h3>Review and edit the generated prompt:</h3>Press "Cancel" to abort the image generation.', 'input', reply, { rows: 5 });
if (refinedPrompt) {
reply = refinedPrompt;
} else {
throw new Error('Generation aborted by user.');
}
}
return reply;
}
async function sendGenerationRequest(prompt, callback) {
@@ -583,7 +604,6 @@ function addSDGenButtons() {
`
const dropdownHtml = `
<div id="sd_dropdown">
<ul class="list-group">
<span>Send me a picture of:</span>
<li class="list-group-item" id="sd_you" data-value="you">Yourself</li>
@@ -750,6 +770,10 @@ jQuery(async () => {
<small><i>Use slash commands or the bottom Paintbrush button to generate images. Type <span class="monospace">/help</span> in chat for more details</i></small>
<br>
<small><i>Hint: Save an API key in Horde KoboldAI API settings to use it here.</i></small>
<label for="sd_refine_mode" class="checkbox_label" title="Allow to edit prompts manually before sending them to generation API">
<input id="sd_refine_mode" type="checkbox" />
Edit prompts before generation
</label>
<div class="flex-container flexGap5 marginTop10 margin-bot-10px">
<label class="checkbox_label">
<input id="sd_horde" type="checkbox" />
@@ -810,6 +834,7 @@ jQuery(async () => {
$('#sd_horde_karras').on('input', onHordeKarrasInput);
$('#sd_restore_faces').on('input', onRestoreFacesInput);
$('#sd_enable_hr').on('input', onHighResFixInput);
$('#sd_refine_mode').on('input', onRefineModeInput);
$('.sd_settings .inline-drawer-toggle').on('click', function () {
initScrollHeight($("#sd_prompt_prefix"));