JoPmt commited on
Commit
512ec5e
·
1 Parent(s): 7a3a3a2

Upload index23.html

Browse files
Files changed (1) hide show
  1. index23.html +364 -0
index23.html ADDED
@@ -0,0 +1,364 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>HuggingFace.API.Model.Stable.Diffusion.To.Canvas.Video</title>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <link rel="stylesheet" href="style.css">
8
+ <style>
9
+ #cloak {
10
+ top:0;
11
+ left:0;
12
+ width: 100%;
13
+ height: 100%;
14
+ display:none;
15
+ position: absolute;
16
+ z-index: 9000;
17
+ background-color: #00000080;
18
+ }
19
+ </style>
20
+ </head>
21
+ <body style="height:100%;width:100%;text-align:center;justify-content:center;background-color:#000000;color:#FFA500;background-position:center;background-repeat:repeat;background-size:contain;">
22
+ <h1 style="padding:4%,4%,4%,4%;">HuggingFace text-to-Stable-Diffusion-to-canvas video?</h1>
23
+ <h6>StabilityAI OpenJourney Runwayml Stable-Diffusion AI Models API Chaining text-to-image,text-to-video Demo</h6>
24
+ <form style="border: solid 1px; border-color: #FFA500;">
25
+ <label for="input-text">Huggingface.Model.Chain.Demo.Interface:</label>
26
+ <br>
27
+ <textarea style="text-align:center;justify-content:center;vertical-align:50%;background-color:#00000070; color: white; border: solid 1px; border-color: #FFA500;" id="input-text" name="input-text" rows="5" cols="40" required></textarea>
28
+ <br>
29
+ <button type="submit">Generate Video</button>
30
+ </form>
31
+ <video style="height:64%;width:36%;display:none;" id="hoowdy" src="" controls="true"></video>
32
+ <center><canvas style="display:block;justify-content:center;" id="javas"></canvas></center>
33
+ <div style="padding:10%;;width:80%;text-align:center;horizontal-align:center;items-align:center;align-items:center;justify-content:center;" id="response-container"></div>
34
+ <div style="text-align:center; display:flex;items-align:center;align-items:center;justify-content:center; overflow:auto;" width="80%" height="30%" id="image-container"></div>
35
+
36
+ <script>
37
+ var javas = document.querySelector('#javas');
38
+ javas.height = window.innerHeight*65/100;
39
+ javas.width = window.innerWidth*65/100;
40
+ var c = javas.getContext('2d');
41
+ javas.style.display = 'none';
42
+
43
+ var form = document.querySelector('form');
44
+ var responseContainer = document.querySelector('#response-container');
45
+ var imgContainer = document.querySelector('#image-container');
46
+ var hldr;
47
+ var meema = "";
48
+ var allumettes = [];
49
+ var bigboy = [];
50
+ var clown = 0;
51
+ var instant = Date.now();
52
+ var startTime=Date.now();
53
+ var cycleTime=1000*1;
54
+ var elapsed = 0;
55
+ var elapsedCycle=0;
56
+ var elapsedCyclePercent=0;
57
+ var moment = 0;
58
+ var frame = 0;
59
+ var jnstant = Date.now();
60
+ var jtartTime=Date.now();
61
+ var jycleTime=1000*1;
62
+ var jlapsed = 0;
63
+ var jlapsedCycle=0;
64
+ var jlapsedCyclePercent=0;
65
+ var joment = 0;
66
+ var jrame = 0;
67
+ var arrow = 0;
68
+ var tarrot = 0;
69
+ var blanket = document.createElement('canvas');
70
+ var deus;
71
+ var du;
72
+ var knot = 'false';
73
+ var vroom = 0;
74
+ var petit = 0;
75
+ var clock = 0;
76
+ var ti = 0;
77
+ var donuty;
78
+ var toik = 0;
79
+ var petot = 0;
80
+
81
+ imgContainer.addEventListener('touchstart', function (event) {
82
+ if (event.target && event.target.matches("img")) {
83
+ document.body.style.backgroundImage = "url('" + event.target.src + "')";
84
+ }
85
+ });
86
+
87
+ function decep(){
88
+ blanket.setAttribute('id','cloak');
89
+ blanket.width = window.innerWidth;
90
+ blanket.height = window.innerHeight;
91
+ document.body.appendChild(blanket);
92
+ deus = document.querySelector('#cloak');
93
+ du = deus.getContext('2d');
94
+ };
95
+
96
+ async function getmages(){
97
+
98
+ async function stabilitytwoone(){
99
+ try {
100
+ var anputText = document.querySelector('#input-text').value;
101
+ var apiUrl = 'https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1';
102
+ var aeaders = new Headers();
103
+ aeaders.append('Authorization', 'Bearer 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');
104
+ aeaders.append('Accept', 'image/jpeg'),
105
+ aeaders.append('Content-Type', 'application/json');
106
+ var aody = JSON.stringify({ inputs: "cinematographic style, 4k, hi-res, dslr style, high-quality, render: " + anputText + " " + Date.now() + "", options: { wait_for_model: true } });
107
+ var aequestOptions = {
108
+ method: 'POST',
109
+ headers: aeaders,
110
+ body: aody,
111
+ responseType: "blob",
112
+ redirect: 'follow',
113
+ };
114
+ var aesponse = await fetch(apiUrl, aequestOptions).then((aesponse) => aesponse.blob()).then((alob) => {
115
+ var abjectURL = URL.createObjectURL(alob);
116
+ var vat = document.createElement('p');
117
+ vat.style.setProperty("border","solid 1px");
118
+ vat.style.setProperty("color","#FFA500");
119
+ vat.style.setProperty("width","18%");
120
+ vat.style.setProperty("display","block");
121
+ vat.style.setProperty("background-color", "#00000080");
122
+ vat.innerHTML = '<img style="object-fit:contain;" width="100%" src="' + abjectURL + '" type="image/jpeg"></img>';
123
+ imgContainer.insertBefore(vat, imgContainer.firstChild);
124
+ vroom += 3;
125
+ }).catch((erran) => { stabilitytwoone(); });
126
+ } catch(errar){ responseContainer.innerHTML += "outerstabilitycatched: " +errar+ ""; };
127
+
128
+ };
129
+
130
+ async function pmpthero(){
131
+ try {
132
+ var bnputText = document.querySelector('#input-text').value;
133
+ var bpiUrl = 'https://api-inference.huggingface.co/models/prompthero/openjourney';
134
+ var beaders = new Headers();
135
+ beaders.append('Authorization', 'Bearer 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');
136
+ beaders.append('Accept', 'image/jpeg'),
137
+ beaders.append('Content-Type', 'application/json');
138
+ var body = JSON.stringify({ inputs: "cinematographic style, 4k, hi-res, dslr style, high-quality, render: " + bnputText + " " + Date.now() + "", options: { wait_for_model: true, } });
139
+ var bequestOptions = {
140
+ method: 'POST',
141
+ headers: beaders,
142
+ body: body,
143
+ responseType: "blob",
144
+ redirect: 'follow',
145
+ };
146
+ var besponse = await fetch(bpiUrl, bequestOptions).then((besponse) => besponse.blob()).then((blob) => {
147
+ var bbjectURL = URL.createObjectURL(blob);
148
+ var vbt = document.createElement('p');
149
+ vbt.style.setProperty("border","solid 1px");
150
+ vbt.style.setProperty("width","18%");
151
+ vbt.style.setProperty("display","block");
152
+ vbt.style.setProperty("color","#FFA500");
153
+ vbt.style.setProperty("background-color", "#00000080");
154
+ vbt.innerHTML += '<img style="object-fit:contain;" width="100%" src="' + bbjectURL + '" type="image/jpeg"></img>';
155
+ imgContainer.insertBefore(vbt, imgContainer.firstChild);
156
+ vroom += 3;
157
+ }).catch((errbn) => { pmpthero(); });
158
+ } catch(errbr){ responseContainer.innerHTML += "outercatched: " +errbr+ ""; };
159
+ };
160
+
161
+ async function ruwayonefive(){
162
+ try {
163
+ var cnputText = document.querySelector('#input-text').value;
164
+ var cpiUrl = 'https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5';
165
+ var ceaders = new Headers();
166
+ ceaders.append('Authorization', 'Bearer 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');
167
+ ceaders.append('Accept', 'image/jpeg'),
168
+ ceaders.append('Content-Type', 'application/json');
169
+ var cody = JSON.stringify({ inputs: "cinematographic style, 4k, hi-res, dslr style, high-quality, render: " + cnputText + " " + Date.now() + "", options: { wait_for_model: true } });
170
+
171
+ var cequestOptions = {
172
+ method: 'POST',
173
+ headers: ceaders,
174
+ body: cody,
175
+ responseType: "blob",
176
+ redirect: 'follow',
177
+ };
178
+ var cesponse = await fetch(cpiUrl, cequestOptions).then((cesponse) => cesponse.blob()).then((clob) => {
179
+ var cbjectURL = URL.createObjectURL(clob);
180
+ var vct = document.createElement('p');
181
+ vct.style.setProperty("border","solid 1px");
182
+ vct.style.setProperty("width","18%");
183
+ vct.style.setProperty("display","block");
184
+ vct.style.setProperty("color","#FFA500");
185
+ vct.style.setProperty("background-color", "#00000080");
186
+ vct.innerHTML += '<img style="object-fit:contain;" width="100%" src="' + cbjectURL + '" type="image/jpeg"></img>';
187
+ imgContainer.insertBefore(vct, imgContainer.firstChild);
188
+ vroom += 3;
189
+ }).catch((errpn) => { ruwayonefive(); });
190
+ } catch(errdr){ responseContainer.innerHTML += "outercatched: " +errdr+ ""; };
191
+ };
192
+
193
+ try {
194
+ await stabilitytwoone();
195
+ await pmpthero();
196
+ await ruwayonefive();
197
+ }catch(egnor){getmages();};
198
+
199
+ tarrot++;
200
+ };
201
+
202
+ function drawFrames() {
203
+ c.font = "16px Arial";
204
+ c.fillStyle = "#FFA500";
205
+ c.fillText("Frame: "+frame, 30, 180);
206
+ c.fill();
207
+ };
208
+
209
+ function drawMomentos() {
210
+ c.font = "16px Arial";
211
+ c.fillStyle = "#FFA500";
212
+ c.fillText("Elapsed: "+elapsed+"ms", 30, 35);
213
+ c.fill();
214
+ };
215
+
216
+ function drawFps() {
217
+ c.font = "16px Arial";
218
+ c.fillStyle = "#FFA500";
219
+ c.fillText("Fps: "+elapsed/frame, 30, 210);
220
+ c.fill();
221
+ };
222
+
223
+ function drawJrames() {
224
+ du.font = "16px Arial";
225
+ du.fillStyle = "#FFA500";
226
+ du.fillText("Frame: "+jrame, (deus.width/2)-150, (deus.height/2)+20);
227
+ du.fill();
228
+ };
229
+
230
+ function drawJomentos() {
231
+ du.font = "16px Arial";
232
+ du.fillStyle = "#FFA500";
233
+ du.fillText("Elapsed: "+jlapsed+"ms", (deus.width/2)-150, (deus.height/2)+40);
234
+ du.fill();
235
+ };
236
+
237
+ function drawJps() {
238
+ du.font = "16px Arial";
239
+ du.fillStyle = "#FFA500";
240
+ du.fillText("fps: "+jlapsed/jrame, (deus.width/2)-150, (deus.height/2)+60);
241
+ du.fill();
242
+ };
243
+
244
+ function jraw(){
245
+ jrame += 1;
246
+ jlapsed=Date.now()-jtartTime;
247
+ jlapsedCycle=elapsed%cycleTime;
248
+ jlapsedCyclePercent=jlapsedCycle/jycleTime;
249
+ joment += jlapsed;
250
+ du.clearRect(0, 0, deus.width, deus.height);
251
+ du.font = "50px Arial";
252
+ du.fillStyle = "#FFA500";
253
+ du.fillText("Building..."+vroom+"%", (deus.width/2)-150, (deus.height/2));
254
+ du.fill();
255
+ drawJomentos();
256
+ };
257
+
258
+ function draw(){
259
+ frame += 1;
260
+ elapsed=Date.now()-startTime;
261
+ elapsedCycle=elapsed%cycleTime;
262
+ elapsedCyclePercent=elapsedCycle/cycleTime;
263
+ moment += elapsed;
264
+ if (frame < clock){
265
+ if (donuty[ti].complete && donuty[ti].naturalHeight !== 0){
266
+ c.clearRect(0, 0, javas.width, javas.height);
267
+ c.drawImage(donuty[ti], 0, 0, javas.width, javas.height);
268
+ c.font = "16px Arial";
269
+ c.fillStyle = "#FFA500";
270
+ c.fill();
271
+ drawMomentos();
272
+ window.requestAnimationFrame(draw);
273
+ }else{ ti++; window.requestAnimationFrame(draw);};
274
+ }
275
+ if (frame == clock){
276
+ clock += 7300;
277
+ if (ti < donuty.length-1){
278
+ ti++;
279
+ }
280
+ if (toik == 3){
281
+ toik = 0;
282
+ petot += 1;
283
+ }
284
+ toik++;
285
+ }
286
+ };
287
+
288
+ joob = setInterval(function(){
289
+ jraw();
290
+ }, 32/1000);
291
+
292
+ noob = setInterval(function(){
293
+ draw();
294
+ }, 32/1000);
295
+
296
+ tinny = setInterval(function(){
297
+ arrow++;
298
+ }, 30000/bigboy.length);
299
+
300
+ winny = setInterval(function(){
301
+ petit++;
302
+ }, 30000/allumettes.length);
303
+
304
+ function recordCanvas(canvas, videoLength) {
305
+ const recordedChunks = [];
306
+ const mediaRecorder = new MediaRecorder(
307
+ canvas.captureStream(32), {mimeType: 'video/webm; codecs=vp8'});
308
+ mediaRecorder.ondataavailable = event => recordedChunks.push(event.data);
309
+ mediaRecorder.onstop = () => {
310
+ const url = URL.createObjectURL(
311
+ new Blob(recordedChunks, {type: "video/webm"}));
312
+ const anchor = document.createElement("a");
313
+ anchor.href = url;
314
+ anchor.download = "video.webm";
315
+ anchor.click();
316
+ //window.URL.revokeObjectURL(url);
317
+ document.querySelector('#javas').style.display = 'none';
318
+ document.querySelector('#cloak').style.display = 'none';
319
+ imgContainer.innerHTML = '';
320
+ vroom = 0;
321
+ document.querySelector('#input-text').value = '';
322
+ ti = 0;
323
+ elapsed = 0;
324
+ frame = 0;
325
+ clock = 0;
326
+
327
+ }
328
+ mediaRecorder.start();
329
+ vroom += 5;
330
+ window.setTimeout(() => {mediaRecorder.stop();vroom=vroom+(100-vroom);}, 30000);
331
+ };
332
+
333
+ function jigo(){
334
+ du.clearRect(0, 0, deus.width, deus.height);
335
+ requestAnimationFrame(joob);
336
+ };
337
+
338
+ try {
339
+ form.addEventListener('submit', async (event) => {
340
+ event.preventDefault();
341
+ decep();
342
+ deus.style.display = 'block';
343
+ for (var tapdance = 0; tapdance < 6; tapdance++){
344
+ await getmages();
345
+
346
+ if (tapdance == 5){
347
+ vroom += 5;
348
+ javas.style.display = 'block';
349
+ donuty = document.getElementsByTagName('img');
350
+ vroom += 10;
351
+ clock = frame + 7300;
352
+ var fowl = donuty.length*6000;
353
+ recordCanvas(javas, 30000);
354
+
355
+ window.requestAnimationFrame(noob);
356
+ }
357
+ };
358
+ jigo();
359
+ });
360
+ } catch(errwr){ responseContainer.innerHTML += "outermaincatched: " +errwr+ ""; };
361
+
362
+ </script>
363
+ </body>
364
+ </html>