-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
329 lines (286 loc) · 14.3 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Digital Dreams</title>
<style>
body { margin: 0; }
</style>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="https://www.digitaldream.io">Digital Dreams</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="https://www.digitaldream.io">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.digitaldream.io/about.html">About</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="http://ai.digitaldream.io/">AI Skybox<span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/[email protected]/build/three.module.js",
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/",
"crypto-js": "https://cdn.skypack.dev/crypto-js"
}
}
</script>
<script type="module">
import CryptoJS from 'crypto-js';
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
var scene;
var camera;
var renderer;
var texture;
var material;
var geometry;
var mesh;
var website = "digitaldream.io"
var preprompt = "a 360 equirectangular panorama,";
var endprompt = "unreal engine, intricate detail, panorama hdri";
var id = "82168bb9-8129-491d-b60b-f139014942c5";
var image_url ="textures/pano_1.jpg";
function loadEnv(url) {
// Fetch file contents
fetch(url)
.then(res => res.text())
.then(text => {
// Split into lines
const lines = text.split('\n');
// Build env object
const env = {};
lines.forEach(line => {
const [key, value] = line.split('=');
env[key] = value;
});
// Set env as window property
window.env = env;
var key = window.env.STABLE_HORDE_API_KEY.toString(CryptoJS.enc.Utf8);
var decrypted = CryptoJS.AES.decrypt(key, website);
window.env.STABLE_HORDE_API_KEY = decrypted.toString(CryptoJS.enc.Utf8);
return env;
});
}
init();
animate();
loadEnv('textures/jokes.txt')
function init() {
// set up a scene, camera, and renderer as global variables
scene = new THREE.Scene();
// set up the camera with variables for field of view, aspect ratio, and near and far clipping planes
camera = new THREE.PerspectiveCamera( 80, window.innerWidth / window.innerHeight, 0.1, 10000 );
// set up the renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// load a random image to start out
var rand = Math.floor(Math.random() * 5) + 1;
// set mapping property of texture to equirectangular
//texture = new THREE.TextureLoader().load( 'textures/city_pano_' + rand + '.png' );
texture = new THREE.TextureLoader().load( 'textures/pano_' + rand + '.jpg' );
texture.mapping = THREE.EquirectangularReflectionMapping;
// create a basic material using the texture we just loaded as a color map
material = new THREE.MeshBasicMaterial( { map: texture } );
// create a sphere geometry (radius, width segments, height segments)
geometry = new THREE.SphereGeometry( 512, 32, 32 );
// invert the geometry on the x-axis so that all of the faces point inward
geometry.scale( - 1, 1, 1 );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
// add orbit controls so that we can pan around with the mouse
const controls = new OrbitControls( camera, renderer.domElement );
//controls.update() must be called after any manual changes to the camera's transform
camera.position.set( 0, 0, 50 );
controls.update();
window.addEventListener('resize', onWindowResize );
}
function animate() {
requestAnimationFrame( animate );
mesh.rotation.y += 0.0005;
//controls.update();
renderer.render( scene, camera );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
$(document).ready(function(){
$("#submit").click(function(){
// get the prompt from the text input field
var prompt = $("#prompt").val();
// create a JSON object with the prompt
var data = {
"prompt": preprompt + " " + prompt + ", " + endprompt,
"params": {
"cfg_scale": 8,
"sampler_name": "k_dpm_2_a",
"height": 512,
"width": 1024,
"steps": 50,
"tiling": false,
"karras": false,
"hires_fix": false,
"clip_skip": 1,
"n": 1,
"denoising_strength": 0.75,
"seed": "2015274653",
"post_processing": [
//"NMKD_Siax"
"RealESRGAN_x4plus"
],
"loras": [
{
"name": "10753",
"model": 0.666,
"clip": 1
}
]
},
"nsfw": true,
"censor_nsfw": false,
"trusted_workers": false,
"models": [
$("#model").val()
],
"r2": true,
"shared": true,
"source_processing": "img2img"
};
// change seed to random value as str
data.params.seed = Math.floor(Math.random() * 10000000000).toString();
// send a POST request to the API
$.ajax({
type: "POST",
url: "https://stablehorde.net/api/v2/generate/async",
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"apikey": window.env.STABLE_HORDE_API_KEY,
"Client-Agent": "[email protected]:0:unknown"
},
success: function(data){
// display the response message and id
//alert("Response: " + data.message + " ID: " + data.id);
// set the id in the text input field
id = data.id;
// check the status of the image generation
checkStatusLoop();
},
failure: function(errMsg) {
alert(errMsg);
}
});
});
$(document).ready(function(){
$("#download").click(function(){
// save image from url
var link = document.createElement('a');
link.download = 'image.webp';
link.href = image_url;
link.click();
});
});
// make a new function to replicate curl
// // curl -X 'GET' \
//'https://stablehorde.net/api/v2/generate/status/82168bb9-8129-491d-b60b-f139014942c5' \
// -H 'accept: application/json' \
// -H 'Client-Agent: unknown:0:unknown'
function checkStatus(){
$.ajax({
type: "GET",
url: "https://stablehorde.net/api/v2/generate/status/" + id,
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Client-Agent": "unknown:0:unknown"
},
success: function(data){
// display the response message and id
//alert("Finished: " + data.finished);
// reset the scene and load new image
scene.remove( mesh );
image_url = data.generations[0].img;
texture = new THREE.TextureLoader().load( data.generations[0].img );
material = new THREE.MeshBasicMaterial( { map: texture } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
animate();
},
failure: function(errMsg) {
alert(errMsg);
}
});
}
// checks status of image generation
function checkStatusLoop(){
// poll every 5 seconds in while loop
var finished = 0;
// get the id from the text input field
// send a GET request to the API
$.ajax({
type: "GET",
url: "https://stablehorde.net/api/v2/generate/check/" + id,
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Client-Agent": "unknown:0:unknown"
},
success: function(data){
// display the response message and id
alert("id: "+ id + "\nProcessing: " + data.processing + "\nFinished: " + data.finished);
// if finished check status and update image
if (data.finished){
checkStatus();
}
else{
const myTimeout = setTimeout(checkStatusLoop, 5000);
}
finished = data.finished;
},
failure: function(errMsg) {
alert(errMsg);
}
});
}
});
</script>
<!-- Add jQuery first, then Popper.js, then Bootstrap JS -->
<!-- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div style="position: absolute; top: 90%; left: 50%; transform: translate(-50%, -50%);">
<!-- Add two buttons at bottom of create with a long text input and centered submit -->
<input type="text" id="prompt" style="width: 100%; height: 50px; font-size: 20px; text-align: center; margin: 0 auto; display: block;" placeholder="Describe a scene">
<!-- Create dropdown to choose model -->
<select id="model" style="width: 100%; height: 50px; font-size: 20px; text-align: center; margin: 0 auto; display: block;">
<option value="Deliberate">Deliberate</option>
<option value="stable_diffusion">Stable Diffusion</option>
<option value="Dreamshaper">Dreamshaper</option>
<option value="ChilloutMix">ChilloutMix</option>
</select>
<button id="submit" style="width: 50%; height: 50px; font-size: 20px; text-align: center; margin: 0 auto; display: block;">Create</button>
<!-- download button -->
<button id="download" style="width: 50%; height: 30px; font-size: 15px; text-align: center; margin: 0 auto; display: block;">Download</button>
</div>
</body>
</html>