xyplon commited on
Commit
5facae8
1 Parent(s): a84f943

Update static/models.js

Browse files
Files changed (1) hide show
  1. static/models.js +184 -184
static/models.js CHANGED
@@ -1,184 +1,184 @@
1
- // DO NOT TRY TO COPY MY UI OR STYLR
2
-
3
-
4
- const div = document.getElementById('imshow');
5
- let width = 1024
6
- let height = 1024
7
- let btn = document.getElementById('btn')
8
- let prompt = document.getElementById('prompt')
9
- let negativePrompt = document.getElementById('negative-prompt')
10
- let model = 'rvx4'
11
- let style = 'Cinematic'
12
-
13
-
14
- const modelElement = document.getElementById('model');
15
- modelElement.addEventListener('change', function() {
16
- model = this.value
17
- if (model == "mobius") {
18
- document.getElementById('guidenceRange').value = 3
19
- document.getElementById('guidenceValue').innerText = 3;
20
- }
21
- if(model=="rvx4"){
22
- document.getElementById('guidenceRange').value = 4
23
- document.getElementById('guidenceValue').innerText = 4;
24
- }
25
- if(model=="sd3"){
26
- document.getElementById('guidenceRange').value = 5
27
- document.getElementById('guidenceValue').innerText = 5;
28
- }
29
- if(model=="animagine"){
30
- document.getElementById('guidenceRange').value = 7
31
- document.getElementById('guidenceValue').innerText = 7;
32
- }
33
- if(model=="sdflash"){
34
- document.getElementById('guidenceRange').value = 3
35
- document.getElementById('guidenceValue').innerText = 3;
36
- document.getElementById('stepValue').innerText = 8
37
-
38
- }
39
- });
40
-
41
- const ratioElement =document.getElementById('ratio')
42
- ratioElement.addEventListener('change',function(){
43
- ratio = this.value
44
- if(ratio == '1:1'){
45
- width = 1024;
46
- height = 1024;
47
- }
48
- else if(ratio == '16:9'){
49
- width = 1024;
50
- height = 576;
51
- }
52
- else if(ratio == "9:16"){
53
- width = 576
54
- height = 1024
55
- }
56
- else if(ratio=="1:2"){
57
- width = 544;
58
- height = 1088;
59
- }
60
- else if(ratio=='4:3'){
61
- width = 896;
62
- height = 672;
63
- }
64
- })
65
-
66
- const styleElement = document.getElementById('style')
67
- styleElement.addEventListener('change',function(){
68
- style = this.value
69
- })
70
-
71
- document.getElementById('stepsRange').addEventListener('input', function() {
72
-
73
- if(model=='sdflash' && Number(document.getElementById('stepValue').innerText)>16){
74
- document.getElementById('stepValue').innerText = 16
75
- }
76
- else {
77
- document.getElementById('stepValue').innerText = this.value;
78
- }
79
-
80
- }
81
- );
82
-
83
- document.getElementById('guidenceRange').addEventListener('input', function() {
84
- document.getElementById('guidenceValue').innerText = this.value;
85
- });
86
-
87
-
88
-
89
-
90
-
91
- function log(msg){
92
- console.log(msg)
93
- }
94
-
95
- let task = 0
96
- btn.onclick = async () => {
97
-
98
- const params = {
99
- 'prompt': prompt.value,
100
- 'negative': negativePrompt.value,
101
- "steps": Number(document.getElementById('stepValue').innerText),
102
- 'scale': Number(document.getElementById('guidenceValue').innerText),
103
- "width": Number(width),
104
- "height": Number(height),
105
- "model": model,
106
- 'style': style
107
- };
108
-
109
-
110
-
111
- async function generateImage(params) {
112
- let loader = document.createElement('div')
113
- loader.id = 'loader'
114
- if (div.firstChild!== loader) {
115
- div.insertBefore(loader, div.firstChild);
116
- }
117
- task+=1
118
- let text = document.createElement('p')
119
- text.style.color = 'white'
120
- let loaderImg = document.createElement('img')
121
- loaderImg.src = 'https://fumesai.web.app/load.gif'
122
- loader.append(loaderImg)
123
- text.innerText = ''
124
-
125
- try {
126
- const response = await fetch('/gen', {
127
- method: 'POST',
128
- headers: {
129
- 'Content-Type': 'application/json',
130
- 'Connection': 'keep-alive',
131
- },
132
- body: JSON.stringify(params)
133
- });
134
-
135
- if (!response.ok) {
136
-
137
- if(response.status==429){
138
- alert('too many requests! 4 concurrent jobs per minute is allowed')
139
- loader.parentNode.removeChild(loader);
140
- return
141
- }
142
- }
143
-
144
- const reader = response.body.getReader();
145
- const decoder = new TextDecoder();
146
- while (true) {
147
- const { done, value } = await reader.read();
148
- if (done) break;
149
-
150
- const chunk = decoder.decode(value, { stream: true });
151
- const lines = chunk.split('\n');
152
-
153
- for (const line of lines) {
154
- if (line.startsWith('data: ')) {
155
- const jsonChunk = JSON.parse(line.substring(6));
156
-
157
- if (jsonChunk.progress === 'done') {
158
-
159
- loader.parentNode.removeChild(loader);
160
- const img = document.createElement('img');
161
- if(jsonChunk.width==1024 && jsonChunk.height==576){
162
- img.id = 'lds'
163
- }
164
- img.src = jsonChunk.img;
165
- if (div.firstChild!== img) {
166
- div.insertBefore(img, div.firstChild);
167
- }
168
-
169
- } else {
170
- text.innerText = `${jsonChunk.progress}%`;
171
- loader.appendChild(text);
172
- }
173
- }
174
- }
175
- }
176
-
177
- } catch (error) {
178
- console.error(error);
179
- }
180
- }
181
- generateImage(params)
182
- generateImage(params)
183
- }
184
-
 
1
+ // DO NOT TRY TO COPY MY UI OR STYLE
2
+
3
+
4
+ const div = document.getElementById('imshow');
5
+ let width = 1024
6
+ let height = 1024
7
+ let btn = document.getElementById('btn')
8
+ let prompt = document.getElementById('prompt')
9
+ let negativePrompt = document.getElementById('negative-prompt')
10
+ let model = 'rvx4'
11
+ let style = 'Cinematic'
12
+
13
+
14
+ const modelElement = document.getElementById('model');
15
+ modelElement.addEventListener('change', function() {
16
+ model = this.value
17
+ if (model == "mobius") {
18
+ document.getElementById('guidenceRange').value = 3
19
+ document.getElementById('guidenceValue').innerText = 3;
20
+ }
21
+ if(model=="rvx4"){
22
+ document.getElementById('guidenceRange').value = 3
23
+ document.getElementById('guidenceValue').innerText = 3;
24
+ }
25
+ if(model=="sd3"){
26
+ document.getElementById('guidenceRange').value = 5
27
+ document.getElementById('guidenceValue').innerText = 5;
28
+ }
29
+ if(model=="animagine"){
30
+ document.getElementById('guidenceRange').value = 7
31
+ document.getElementById('guidenceValue').innerText = 7;
32
+ }
33
+ if(model=="sdflash"){
34
+ document.getElementById('guidenceRange').value = 3
35
+ document.getElementById('guidenceValue').innerText = 3;
36
+ document.getElementById('stepValue').innerText = 8
37
+
38
+ }
39
+ });
40
+
41
+ const ratioElement =document.getElementById('ratio')
42
+ ratioElement.addEventListener('change',function(){
43
+ ratio = this.value
44
+ if(ratio == '1:1'){
45
+ width = 1024;
46
+ height = 1024;
47
+ }
48
+ else if(ratio == '16:9'){
49
+ width = 1024;
50
+ height = 576;
51
+ }
52
+ else if(ratio == "9:16"){
53
+ width = 576
54
+ height = 1024
55
+ }
56
+ else if(ratio=="1:2"){
57
+ width = 544;
58
+ height = 1088;
59
+ }
60
+ else if(ratio=='4:3'){
61
+ width = 896;
62
+ height = 672;
63
+ }
64
+ })
65
+
66
+ const styleElement = document.getElementById('style')
67
+ styleElement.addEventListener('change',function(){
68
+ style = this.value
69
+ })
70
+
71
+ document.getElementById('stepsRange').addEventListener('input', function() {
72
+
73
+ if(model=='sdflash' && Number(document.getElementById('stepValue').innerText)>16){
74
+ document.getElementById('stepValue').innerText = 16
75
+ }
76
+ else {
77
+ document.getElementById('stepValue').innerText = this.value;
78
+ }
79
+
80
+ }
81
+ );
82
+
83
+ document.getElementById('guidenceRange').addEventListener('input', function() {
84
+ document.getElementById('guidenceValue').innerText = this.value;
85
+ });
86
+
87
+
88
+
89
+
90
+
91
+ function log(msg){
92
+ console.log(msg)
93
+ }
94
+
95
+ let task = 0
96
+ btn.onclick = async () => {
97
+
98
+ const params = {
99
+ 'prompt': prompt.value,
100
+ 'negative': negativePrompt.value,
101
+ "steps": Number(document.getElementById('stepValue').innerText),
102
+ 'scale': Number(document.getElementById('guidenceValue').innerText),
103
+ "width": Number(width),
104
+ "height": Number(height),
105
+ "model": model,
106
+ 'style': style
107
+ };
108
+
109
+
110
+
111
+ async function generateImage(params) {
112
+ let loader = document.createElement('div')
113
+ loader.id = 'loader'
114
+ if (div.firstChild!== loader) {
115
+ div.insertBefore(loader, div.firstChild);
116
+ }
117
+ task+=1
118
+ let text = document.createElement('p')
119
+ text.style.color = 'white'
120
+ let loaderImg = document.createElement('img')
121
+ loaderImg.src = 'https://fumesai.web.app/load.gif'
122
+ loader.append(loaderImg)
123
+ text.innerText = ''
124
+
125
+ try {
126
+ const response = await fetch('/gen', {
127
+ method: 'POST',
128
+ headers: {
129
+ 'Content-Type': 'application/json',
130
+ 'Connection': 'keep-alive',
131
+ },
132
+ body: JSON.stringify(params)
133
+ });
134
+
135
+ if (!response.ok) {
136
+
137
+ if(response.status==429){
138
+ alert('too many requests! 4 concurrent jobs per minute is allowed')
139
+ loader.parentNode.removeChild(loader);
140
+ return
141
+ }
142
+ }
143
+
144
+ const reader = response.body.getReader();
145
+ const decoder = new TextDecoder();
146
+ while (true) {
147
+ const { done, value } = await reader.read();
148
+ if (done) break;
149
+
150
+ const chunk = decoder.decode(value, { stream: true });
151
+ const lines = chunk.split('\n');
152
+
153
+ for (const line of lines) {
154
+ if (line.startsWith('data: ')) {
155
+ const jsonChunk = JSON.parse(line.substring(6));
156
+
157
+ if (jsonChunk.progress === 'done') {
158
+
159
+ loader.parentNode.removeChild(loader);
160
+ const img = document.createElement('img');
161
+ if(jsonChunk.width==1024 && jsonChunk.height==576){
162
+ img.id = 'lds'
163
+ }
164
+ img.src = jsonChunk.img;
165
+ if (div.firstChild!== img) {
166
+ div.insertBefore(img, div.firstChild);
167
+ }
168
+
169
+ } else {
170
+ text.innerText = `${jsonChunk.progress}%`;
171
+ loader.appendChild(text);
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ } catch (error) {
178
+ console.error(error);
179
+ }
180
+ }
181
+ generateImage(params)
182
+ generateImage(params)
183
+ }
184
+