Skip to content

Commit 2995107

Browse files
committed
added ctrl+up or ctrl+down hotkeys for attention
1 parent b34b25b commit 2995107

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Check the [custom scripts](https://github.com/AUTOMATIC1111/stable-diffusion-web
1616
- Attention, specify parts of text that the model should pay more attention to
1717
- a man in a ((tuxedo)) - will pay more attention to tuxedo
1818
- a man in a (tuxedo:1.21) - alternative syntax
19+
- select text and press ctrl+up or ctrl+down to aduotmatically adjust attention to selected text
1920
- Loopback, run img2img processing multiple times
2021
- X/Y plot, a way to draw a 2 dimensional plot of images with different parameters
2122
- Textual Inversion
@@ -61,6 +62,9 @@ Check the [custom scripts](https://github.com/AUTOMATIC1111/stable-diffusion-web
6162
- Reloading checkpoints on the fly
6263
- Checkpoint Merger, a tab that allows you to merge two checkpoints into one
6364
- [Custom scripts](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts) with many extensions from community
65+
- [Composable-Diffusion](https://energy-based-model.github.io/Compositional-Visual-Generation-with-Composable-Diffusion-Models/), a way to use multiple prompts at once
66+
- separate prompts using uppercase `AND`
67+
- also supports weights for prompts: `a cat :1.2 AND a dog AND a penguin :2.2`
6468

6569
## Installation and Running
6670
Make sure the required [dependencies](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Dependencies) are met and follow the instructions available for both [NVidia](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-NVidia-GPUs) (recommended) and [AMD](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-AMD-GPUs) GPUs.

javascript/edit-attention.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
addEventListener('keydown', (event) => {
2+
let target = event.originalTarget;
3+
if (!target.hasAttribute("placeholder")) return;
4+
if (!target.placeholder.toLowerCase().includes("prompt")) return;
5+
6+
let plus = "ArrowUp"
7+
let minus = "ArrowDown"
8+
if (event.key != plus && event.key != minus) return;
9+
10+
selectionStart = target.selectionStart;
11+
selectionEnd = target.selectionEnd;
12+
if(selectionStart == selectionEnd) return;
13+
14+
event.preventDefault();
15+
16+
if (selectionStart == 0 || target.value[selectionStart - 1] != "(") {
17+
target.value = target.value.slice(0, selectionStart) +
18+
"(" + target.value.slice(selectionStart, selectionEnd) + ":1.0)" +
19+
target.value.slice(selectionEnd);
20+
21+
target.focus();
22+
target.selectionStart = selectionStart + 1;
23+
target.selectionEnd = selectionEnd + 1;
24+
25+
} else {
26+
end = target.value.slice(selectionEnd + 1).indexOf(")") + 1;
27+
weight = parseFloat(target.value.slice(selectionEnd + 1, selectionEnd + 1 + end));
28+
if (event.key == minus) weight -= 0.1;
29+
if (event.key == plus) weight += 0.1;
30+
31+
weight = parseFloat(weight.toPrecision(12));
32+
33+
target.value = target.value.slice(0, selectionEnd + 1) +
34+
weight +
35+
target.value.slice(selectionEnd + 1 + end - 1);
36+
37+
target.focus();
38+
target.selectionStart = selectionStart;
39+
target.selectionEnd = selectionEnd;
40+
}
41+
});

0 commit comments

Comments
 (0)