#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

@@ -2865,7 +2865,7 @@
<div id="dialogue_popup_text"> <div id="dialogue_popup_text">
<h3>text</h3> <h3>text</h3>
</div> </div>
<input id="dialogue_popup_input" class="text_pole" type="text" /> <textarea id="dialogue_popup_input" class="text_pole" rows="1"></textarea>
<div id="dialogue_popup_controls"> <div id="dialogue_popup_controls">
<div id="dialogue_popup_ok" class="menu_button" data-i18n="Delete">Delete</div> <div id="dialogue_popup_ok" class="menu_button" data-i18n="Delete">Delete</div>
<div id="dialogue_popup_cancel" class="menu_button" data-i18n="Cancel">Cancel</div> <div id="dialogue_popup_cancel" class="menu_button" data-i18n="Cancel">Cancel</div>

View File

@@ -5531,7 +5531,7 @@ function onScenarioOverrideRemoveClick() {
$(this).closest('.scenario_override').find('.chat_scenario').val('').trigger('input'); $(this).closest('.scenario_override').find('.chat_scenario').val('').trigger('input');
} }
function callPopup(text, type, inputValue = '', okButton) { function callPopup(text, type, inputValue = '', { okButton, rows } = {}) {
if (type) { if (type) {
popup_type = type; popup_type = type;
} }
@@ -5559,6 +5559,7 @@ function callPopup(text, type, inputValue = '', okButton) {
} }
$("#dialogue_popup_input").val(inputValue); $("#dialogue_popup_input").val(inputValue);
$("#dialogue_popup_input").attr("rows", rows ?? 1);
if (popup_type == 'input') { if (popup_type == 'input') {
$("#dialogue_popup_input").css("display", "block"); $("#dialogue_popup_input").css("display", "block");

View File

@@ -10,7 +10,7 @@ async function doDiceRoll(customDiceFormula) {
let value = typeof customDiceFormula === 'string' ? customDiceFormula.trim() : $(this).data('value'); let value = typeof customDiceFormula === 'string' ? customDiceFormula.trim() : $(this).data('value');
if (value == 'custom') { if (value == 'custom') {
value = await callPopup('Enter the dice formula:<br><i>(for example, <tt>2d6</tt>)</i>', 'input');x value = await callPopup('Enter the dice formula:<br><i>(for example, <tt>2d6</tt>)</i>', 'input');
} }
if (!value) { if (!value) {

View File

@@ -11,7 +11,7 @@ async function saveRegexScript(regexScript, existingScriptIndex) {
toastr.error(`Could not save regex script: The script name was undefined or empty!`); toastr.error(`Could not save regex script: The script name was undefined or empty!`);
return; return;
} }
// Does the script name already exist? // Does the script name already exist?
if (extension_settings.regex.find((e) => e.scriptName === regexScript.scriptName)) { if (extension_settings.regex.find((e) => e.scriptName === regexScript.scriptName)) {
toastr.error(`Could not save regex script: A script with name ${regexScript.scriptName} already exists.`); toastr.error(`Could not save regex script: A script with name ${regexScript.scriptName} already exists.`);
@@ -144,7 +144,7 @@ async function onRegexEditorOpenClick(existingId) {
.prop("checked", true); .prop("checked", true);
} }
const popupResult = await callPopup(editorHtml, "confirm", undefined, "Save"); const popupResult = await callPopup(editorHtml, "confirm", undefined, { okButton: "Save" });
if (popupResult) { if (popupResult) {
const newRegexScript = { const newRegexScript = {
scriptName: editorHtml.find(".regex_script_name").val(), scriptName: editorHtml.find(".regex_script_name").val(),

View File

@@ -131,6 +131,9 @@ const defaultSettings = {
horde: false, horde: false,
horde_nsfw: false, horde_nsfw: false,
horde_karras: true, horde_karras: true,
// Refine mode
refine_mode: false,
} }
async function loadSettings() { async function loadSettings() {
@@ -149,10 +152,16 @@ async function loadSettings() {
$('#sd_horde_karras').prop('checked', extension_settings.sd.horde_karras); $('#sd_horde_karras').prop('checked', extension_settings.sd.horde_karras);
$('#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_refine_mode').prop('checked', extension_settings.sd.refine_mode);
await Promise.all([loadSamplers(), loadModels()]); await Promise.all([loadSamplers(), loadModels()]);
} }
function onRefineModeInput() {
extension_settings.sd.refine_mode = !!$('#sd_refine_mode').prop('checked');
saveSettingsDebounced();
}
function onScaleInput() { function onScaleInput() {
extension_settings.sd.scale = Number($('#sd_scale').val()); extension_settings.sd.scale = Number($('#sd_scale').val());
$('#sd_scale_value').text(extension_settings.sd.scale.toFixed(1)); $('#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) { async function generatePrompt(quiet_prompt) {
return processReply(await new Promise( let reply = processReply(await new Promise(
async function promptPromise(resolve, reject) { async function promptPromise(resolve, reject) {
try { try {
await getContext().generate('quiet', { resolve, reject, quiet_prompt, force_name2: true, }); await getContext().generate('quiet', { resolve, reject, quiet_prompt, force_name2: true, });
@@ -479,6 +488,18 @@ async function generatePrompt(quiet_prompt) {
reject(); 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) { async function sendGenerationRequest(prompt, callback) {
@@ -583,7 +604,6 @@ function addSDGenButtons() {
` `
const dropdownHtml = ` const dropdownHtml = `
<div id="sd_dropdown"> <div id="sd_dropdown">
<ul class="list-group"> <ul class="list-group">
<span>Send me a picture of:</span> <span>Send me a picture of:</span>
<li class="list-group-item" id="sd_you" data-value="you">Yourself</li> <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> <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> <br>
<small><i>Hint: Save an API key in Horde KoboldAI API settings to use it here.</i></small> <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"> <div class="flex-container flexGap5 marginTop10 margin-bot-10px">
<label class="checkbox_label"> <label class="checkbox_label">
<input id="sd_horde" type="checkbox" /> <input id="sd_horde" type="checkbox" />
@@ -810,6 +834,7 @@ jQuery(async () => {
$('#sd_horde_karras').on('input', onHordeKarrasInput); $('#sd_horde_karras').on('input', onHordeKarrasInput);
$('#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_refine_mode').on('input', onRefineModeInput);
$('.sd_settings .inline-drawer-toggle').on('click', function () { $('.sd_settings .inline-drawer-toggle').on('click', function () {
initScrollHeight($("#sd_prompt_prefix")); initScrollHeight($("#sd_prompt_prefix"));