Skip to content

Commit 919958c

Browse files
committed
sd webui code
1 parent b083ba8 commit 919958c

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

08-image-models/sd-webui/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.1/p5.js"></script>
5+
<meta charset="utf-8" />
6+
</head>
7+
<body>
8+
<main></main>
9+
<script src="sketch.js"></script>
10+
</body>
11+
</html>

08-image-models/sd-webui/sketch.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
let promptInput;
2+
let submitButton;
3+
let img;
4+
let loading = false;
5+
6+
function setup() {
7+
createCanvas(400, 400);
8+
promptInput = createInput('A land of rainbows.');
9+
submitButton = createButton('generate');
10+
submitButton.mousePressed(generateImage);
11+
}
12+
13+
function draw() {
14+
background(220);
15+
if (loading) {
16+
textAlign(CENTER, CENTER);
17+
text('Loading...', width / 2, height / 2);
18+
} else if (img) {
19+
image(img, 0, 0, width, height);
20+
}
21+
}
22+
23+
async function generateImage() {
24+
loading = true;
25+
const response = await fetch('http://itp-ml.itp.tsoa.nyu.edu:7860/sdapi/v1/txt2img', {
26+
method: 'POST',
27+
headers: {
28+
'Content-Type': 'application/json',
29+
},
30+
body: JSON.stringify({
31+
prompt: promptInput.value(),
32+
}),
33+
});
34+
35+
const data = await response.json();
36+
img = createImg('data:image/png;base64,' + data.images[0], promptInput.value());
37+
img.hide();
38+
loading = false;
39+
}

0 commit comments

Comments
 (0)