-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
255 lines (233 loc) · 7.48 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html>
<html>
<head>
<title>You Have Arrived</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
var seqno = 0
var newSeed = '0'
var nSteps = 4
var guidance = 8.0
var mergeRatio = 50
var imgfry = 1.0
function newseed() {
newSeed = '1'
update()
newSeed = '0'
}
var is_generating = false
var has_changed = false
var inputData
function update() {
var width = 512;
var height = 512;
if (is_generating) {
has_changed = true
inputData = {
newSeed: newSeed,
width: width,
height: height,
nSteps: nSteps,
guidance: guidance,
prompt: $('#prompt').val(),
negative: $('#negative').val(),
mergeRatio: mergeRatio,
imgfry: imgfry,
}
} else {
inputData = {
newSeed: newSeed,
width: width,
height: height,
nSteps: nSteps,
guidance: guidance,
prompt: $('#prompt').val(),
negative: $('#negative').val(),
mergeRatio: mergeRatio,
imgfry: imgfry,
}
generate()
}
}
function generate() {
is_generating = true;
has_changed = false;
$.ajax({
url: '/submit',
type: 'POST',
data: JSON.stringify(inputData),
contentType: 'application/json',
dataType: 'json',
success: function(response) {
if (response.image) {
const imageContainer = document.querySelector('.imageContainer');
var image = new Image();
image.src = 'data:image/jpeg;base64,' + response.image;
while (imageContainer.firstChild) {
imageContainer.removeChild(imageContainer.firstChild);
}
$('.imageContainer').prepend(image);
} else {
var message = $('<p>').text(response.message);
$('.imageContainer').prepend(message);
alert(response.message)
}
is_generating = false;
if (has_changed) {
generate();
}
},
error: function() {
is_generating = false;
alert('An error occurred during submission.');
if (has_changed) {
generate()
}
}
});
}
$(document).ready(function() {
slider = document.querySelector('#mergeRatioSlider');
// Add an event listener to the slider.
//slider.oninput = function(event) {
slider.addEventListener('input', function(event) {
tm = performance.now()
console.log('IN: Merge slide: ' + tm)
mergeRatio = event.target.value;
// TODO: Cache for performance
var txt = document.getElementById('mergeValue');
txt.textContent = mergeRatio
update()
tm = performance.now()
console.log('OUT: Merge slide' + tm)
});
slider = document.querySelector('#guidanceSlider');
// Add an event listener to the slider.
slider.addEventListener('input', function(event) {
guidance = event.target.value;
// TODO: Cache for performance
var txt = document.getElementById('guidanceValue');
txt.textContent = guidance
update()
});
slider = document.querySelector('#stepsSlider');
// Add an event listener to the slider.
slider.addEventListener('input', function(event) {
nSteps = event.target.value;
// TODO: Cache for performance
var txt = document.getElementById('stepsValue');
txt.textContent = nSteps
update()
});
slider = document.querySelector('#imgfrySlider');
// Add an event listener to the slider.
slider.addEventListener('input', function(event) {
imgfry = event.target.value;
// TODO: Cache for performance
var txt = document.getElementById('imgfryValue');
txt.textContent = imgfry
update()
});
$('#submitForm').submit(function(event) {
event.preventDefault();
var submitButtonId = event.originalEvent.submitter.id
update()
});
});
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.main-container {
display: flex;
align-items: flex-start;
}
.imageContainer {
width: 512px;
height: 512px;
border: 2px red;
}
.slidersContainer {
display: flex;
flex-direction: column;
align-items: flex-start;
background-color: lightgray;
border: 2px solid darkgray;
height: 508px;
}
.sliderContainer {
display: flex;
align-items: center;
width: 67%;
}
.sliderLabel {
font-size: 22px;
width: 144px;
}
.sliderValue {
font-size: 22px;
width: 40px;
}
#generate {
font-size: 24px;
}
#newseed {
font-size: 24px;
}
body {
font-size: 22px;
}
.slider {
width: 70%;
}
.title-text {
font-family: 'Arial Black', sans-serif;
font-size: 36px;
color: blue;
text-align: center;
text-transform: uppercase;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
</style>
</head>
<body>
<script>
</script>
<div class="title-text">RTSD - Where Dreams Come True!</div>
<hr>
<div class="main-container">
<div class="imageContainer"></div>
<div class="slidersContainer">
<div class="sliderContainer">
<span class="sliderLabel">Merge Ratio</span>
<span class="sliderValue" id="mergeValue">50</span>
<input type="range" class="slider" id="mergeRatioSlider" min=0 max=100 value=50>
</div>
<div class="sliderContainer">
<br><span class="sliderLabel">Guidance</span>
<span class="sliderValue" id="guidanceValue">8.0</span>
<input type="range" class="slider" id="guidanceSlider" min=.5 max=20.0 value=8. step=.5>
</div>
<div class="sliderContainer">
<br><span class="sliderLabel">Steps</span>
<span class="sliderValue" id="stepsValue"> 4</span>
<input type="range" class="slider" id="stepsSlider" min=1 max=20 value=4>
</div>
<div class="sliderContainer">
<br><span class="sliderLabel">Image Fry</span>
<span class="sliderValue" id="imgfryValue"> 1.0</span>
<input type="range" class="slider" id="imgfrySlider" min=0.25 max=4.0 value=1.0 step=0.05>
</div>
<br><br>
<code>Prompt 1</code> <textarea id="prompt" placeholder="Tell me your fantasy!" rows="5" cols="64" maxlength="4096"></textarea><br>
<code>Prompt 2</code> <textarea id="negative" placeholder="What requires eye bleach?" rows="5" cols="64" maxlength="4096"></textarea><br><br>
</div>
</div>
<div id="generate">
<form id="submitForm">
<button type="submit" id="generate">Generate</button>
</form>
<button id="newseed" onclick="newseed()">New seed</button>
</div>
<hr>
</body>
</html>