artdwn/stable-diffusion-backup
Stable Diffusion web UI A browser interface based on Gradio library for Stable Diffusion. Features Detailed feature showcase with images: Original txt2img and img2img modes One click install and run script (but you still must install python and git) Outpainting Inpainting Color Sketch Prompt Matrix Stable Diffusion Upscale Attention, specify parts of text that the model should pay more attention to a man in a ((tuxedo)) - will pay more attention to tuxedo a man… See the full description on the dataset page: https://huggingface.co/datasets/artdwn/stable-diffusion-backup.
11.1k
1function keyupEditAttention(event) {2 let target = event.originalTarget || event.composedPath()[0];3 if (!target.matches("*:is([id*='_toprow'] [id*='_prompt'], .prompt) textarea")) return;4 if (!(event.metaKey || event.ctrlKey)) return;5 6 let isPlus = event.key == "ArrowUp";7 let isMinus = event.key == "ArrowDown";8 if (!isPlus && !isMinus) return;9 10 let selectionStart = target.selectionStart;11 let selectionEnd = target.selectionEnd;12 let text = target.value;13 14 function selectCurrentParenthesisBlock(OPEN, CLOSE) {15 if (selectionStart !== selectionEnd) return false;16 17 // Find opening parenthesis around current cursor18 const before = text.substring(0, selectionStart);19 let beforeParen = before.lastIndexOf(OPEN);20 if (beforeParen == -1) return false;21 let beforeParenClose = before.lastIndexOf(CLOSE);22 while (beforeParenClose !== -1 && beforeParenClose > beforeParen) {23 beforeParen = before.lastIndexOf(OPEN, beforeParen - 1);24 beforeParenClose = before.lastIndexOf(CLOSE, beforeParenClose - 1);25 }26 27 // Find closing parenthesis around current cursor28 const after = text.substring(selectionStart);29 let afterParen = after.indexOf(CLOSE);30 if (afterParen == -1) return false;31 let afterParenOpen = after.indexOf(OPEN);32 while (afterParenOpen !== -1 && afterParen > afterParenOpen) {33 afterParen = after.indexOf(CLOSE, afterParen + 1);34 afterParenOpen = after.indexOf(OPEN, afterParenOpen + 1);35 }36 if (beforeParen === -1 || afterParen === -1) return false;37 38 // Set the selection to the text between the parenthesis39 const parenContent = text.substring(beforeParen + 1, selectionStart + afterParen);40 const lastColon = parenContent.lastIndexOf(":");41 selectionStart = beforeParen + 1;42 selectionEnd = selectionStart + lastColon;43 target.setSelectionRange(selectionStart, selectionEnd);44 return true;45 }46 47 function selectCurrentWord() {48 if (selectionStart !== selectionEnd) return false;49 const delimiters = opts.keyedit_delimiters + " \r\n\t";50 51 // seek backward until to find beggining52 while (!delimiters.includes(text[selectionStart - 1]) && selectionStart > 0) {53 selectionStart--;54 }55 56 // seek forward to find end57 while (!delimiters.includes(text[selectionEnd]) && selectionEnd < text.length) {58 selectionEnd++;59 }60 61 target.setSelectionRange(selectionStart, selectionEnd);62 return true;63 }64 65 // If the user hasn't selected anything, let's select their current parenthesis block or word66 if (!selectCurrentParenthesisBlock('<', '>') && !selectCurrentParenthesisBlock('(', ')')) {67 selectCurrentWord();68 }69 70 event.preventDefault();71 72 var closeCharacter = ')';73 var delta = opts.keyedit_precision_attention;74 75 if (selectionStart > 0 && text[selectionStart - 1] == '<') {76 closeCharacter = '>';77 delta = opts.keyedit_precision_extra;78 } else if (selectionStart == 0 || text[selectionStart - 1] != "(") {79 80 // do not include spaces at the end81 while (selectionEnd > selectionStart && text[selectionEnd - 1] == ' ') {82 selectionEnd -= 1;83 }84 if (selectionStart == selectionEnd) {85 return;86 }87 88 text = text.slice(0, selectionStart) + "(" + text.slice(selectionStart, selectionEnd) + ":1.0)" + text.slice(selectionEnd);89 90 selectionStart += 1;91 selectionEnd += 1;92 }93 94 var end = text.slice(selectionEnd + 1).indexOf(closeCharacter) + 1;95 var weight = parseFloat(text.slice(selectionEnd + 1, selectionEnd + 1 + end));96 if (isNaN(weight)) return;97 98 weight += isPlus ? delta : -delta;99 weight = parseFloat(weight.toPrecision(12));100 if (String(weight).length == 1) weight += ".0";101 102 if (closeCharacter == ')' && weight == 1) {103 var endParenPos = text.substring(selectionEnd).indexOf(')');104 text = text.slice(0, selectionStart - 1) + text.slice(selectionStart, selectionEnd) + text.slice(selectionEnd + endParenPos + 1);105 selectionStart--;106 selectionEnd--;107 } else {108 text = text.slice(0, selectionEnd + 1) + weight + text.slice(selectionEnd + end);109 }110 111 target.focus();112 target.value = text;113 target.selectionStart = selectionStart;114 target.selectionEnd = selectionEnd;115 116 updateInput(target);117}118 119addEventListener('keydown', (event) => {120 keyupEditAttention(event);121});122 