Skip to content

Commit 925de50

Browse files
authored
Merge pull request #316 from AEtheve/estimation-time-and-outpainting
Add estimation of remaining time + new features in outpainting
2 parents 36386f1 + 8c4efbf commit 925de50

File tree

8 files changed

+102
-25
lines changed

8 files changed

+102
-25
lines changed

electron_app/src/StableDiffusion.vue

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
66
import { send_to_py } from "./py_vue_bridge.js"
77
import {get_tokens} from './clip_tokeniser/clip_encoder.js'
8+
import {compute_time_remaining} from "./utils.js"
9+
const moment = require('moment')
810
911
let notification_sound = new Audio(require('@/assets/notification.mp3'))
1012
@@ -33,8 +35,12 @@ export default {
3335
model_loading_title : "",
3436
loading_percentage : -1 ,
3537
generation_state_msg : "",
38+
remaining_times: "",
3639
attached_cbs : undefined,
3740
model_version : "",
41+
nb_its: 0,
42+
iter_times: [],
43+
generation_loop: undefined
3844
};
3945
},
4046
methods: {
@@ -136,8 +142,23 @@ export default {
136142
this.last_iter_t = Date.now();
137143
if(this.attached_cbs){
138144
if(this.attached_cbs.on_progress){
139-
if(p >= 0 )
145+
if(p >= 0 ){
140146
this.generation_state_msg = iter_time/1000 + " s/it";
147+
this.iter_times.push(iter_time);
148+
let median = this.iter_times.sort((a, b) => a - b)[Math.floor(this.iter_times.length / 2)];
149+
let time_remaining = moment.duration(median*((100-p)*this.nb_its/100));
150+
151+
this.remaining_times = compute_time_remaining(time_remaining);
152+
clearInterval(this.generation_loop);
153+
this.generation_loop = setInterval(() => {
154+
if(this.attached_cbs == undefined){
155+
return clearInterval(this.generation_loop);
156+
}
157+
time_remaining.subtract(1, 'seconds');
158+
this.remaining_times = compute_time_remaining(time_remaining);
159+
}, 1000);
160+
161+
}
141162
this.attached_cbs.on_progress(p, iter_time);
142163
}
143164
@@ -149,7 +170,8 @@ export default {
149170
} ,
150171
151172
interupt(){
152-
send_to_py("t2im __stop__")
173+
send_to_py("t2im __stop__")
174+
this.attached_cbs = undefined;
153175
},
154176
155177
text_to_img(prompt_params, callbacks, generated_by){
@@ -180,6 +202,9 @@ export default {
180202
this.generated_by = generated_by;
181203
this.attached_cbs = callbacks;
182204
this.generation_state_msg = ""
205+
this.remaining_times = ""
206+
this.iter_times = []
207+
this.nb_its = prompt_params.ddim_steps||25
183208
send_to_py("t2im " + JSON.stringify(prompt_params))
184209
}
185210

electron_app/src/components/Img2Img.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
</div>
7676

7777
<div v-if="!stable_diffusion.is_input_avail && stable_diffusion.generated_by=='img2img'">
78-
<LoaderModal :loading_percentage="done_percentage" loading_title="Generating" :loading_desc="stable_diffusion.generation_state_msg"></LoaderModal>
78+
<LoaderModal :loading_percentage="done_percentage" loading_title="Generating" :loading_desc="stable_diffusion.generation_state_msg" :remaining_times="stable_diffusion.remaining_times"></LoaderModal>
7979
</div>
8080

8181

electron_app/src/components/ImgGenerate.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
</div>
102102

103103
<div v-if="!stable_diffusion.is_input_avail && stable_diffusion.generated_by=='txt2img'">
104-
<LoaderModal :loading_percentage="done_percentage" loading_title="Generating" :loading_desc="stable_diffusion.generation_state_msg"></LoaderModal>
104+
<LoaderModal :loading_percentage="done_percentage" loading_title="Generating" :loading_desc="stable_diffusion.generation_state_msg" :remaining_times="stable_diffusion.remaining_times"></LoaderModal>
105105
</div>
106106

107107
<div class="bottom_float">

electron_app/src/components/Inpainting.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</div>
5454

5555
<div v-if="!stable_diffusion.is_input_avail && stable_diffusion.generated_by=='inpainting'">
56-
<LoaderModal :loading_percentage="done_percentage" loading_title="Generating" :loading_desc="stable_diffusion.generation_state_msg"></LoaderModal>
56+
<LoaderModal :loading_percentage="done_percentage" loading_title="Generating" :loading_desc="stable_diffusion.generation_state_msg" :remaining_times="stable_diffusion.remaining_times"></LoaderModal>
5757
</div>
5858

5959

electron_app/src/components/Outpainting.vue

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@
1818
style="border-radius: 12px 12px 12px 12px; width: calc(100%); resize: none; "
1919
class="form-control outpaint_textbox"
2020
v-bind:class="{ 'disabled' : !stable_diffusion.is_input_avail}"
21-
:rows="2">
21+
:rows="is_negative_prompt_avail ? 1:2">
22+
</textarea>
23+
<textarea
24+
v-if="is_negative_prompt_avail"
25+
v-model="negative_prompt"
26+
placeholder="Enter your negative prompt here"
27+
style="border-radius: 12px 12px 12px 12px; width: calc(100%);font-size:13px; margin-top:14px; resize: none; "
28+
class="form-control outpaint_textbox"
29+
v-bind:class="{ 'disabled' : !stable_diffusion.is_input_avail}"
30+
:rows="is_negative_prompt_avail ? 1:2">
2231
</textarea>
2332

2433

2534

2635

27-
<div v-if="stable_diffusion.is_input_avail" style="margin-top: 20px">
28-
36+
<div v-if="stable_diffusion.is_input_avail" style="margin-top: 15px">
37+
<SDOptionsDropdown :style="is_negative_prompt_avail?'margin-top:-43px':''" :options_model_values="this_object" :elements_hidden="[ 'num_imgs', 'inp_img_strength', 'batch_size', 'guidence_scale', 'img_h', 'custom_model', 'seed']"> </SDOptionsDropdown>
2938
<div class="l_button button_medium button_colored" style="float:right ; " @click="generate()" >Generate</div>
30-
31-
3239
</div>
3340
<span v-else-if="stable_diffusion.generated_by=='outpainting'" >
3441
<div v-if="is_stopping" class="l_button button_medium button_colored" style="float:right; float:right ; margin-top: 20px; " @click="stop_generation">Stopping ...</div>
@@ -43,7 +50,7 @@
4350
</div>
4451

4552
<div v-if="!stable_diffusion.is_input_avail && stable_diffusion.generated_by=='outpainting'">
46-
<LoaderModal :loading_percentage="done_percentage" loading_title="Generating" :loading_desc="stable_diffusion.generation_state_msg"></LoaderModal>
53+
<LoaderModal :loading_percentage="done_percentage" loading_title="Generating" :loading_desc="stable_diffusion.generation_state_msg" :remaining_times="stable_diffusion.remaining_times"></LoaderModal>
4754
</div>
4855

4956
<p style="opacity:0.5; zoom:0.8; float:left; max-width: calc(100vw - 200px); margin-bottom: 0; "> Please describe image you want to draw in the box. </p>
@@ -54,6 +61,7 @@
5461
import Konva from 'konva';
5562
import LoaderModal from '../components_bare/LoaderModal.vue'
5663
import Vue from 'vue'
64+
import SDOptionsDropdown from '../components_bare/SDOptionsDropdown.vue'
5765
5866
function onVisible(element, callback) {
5967
new IntersectionObserver((entries, observer) => {
@@ -74,7 +82,7 @@ export default {
7482
app_state : Object ,
7583
stable_diffusion : Object,
7684
},
77-
components: {LoaderModal},
85+
components: {LoaderModal, SDOptionsDropdown},
7886
mounted() {
7987
this.init_state();
8088
this.resize_stage()
@@ -94,6 +102,9 @@ export default {
94102
95103
is_earasing: false,
96104
is_eraser_enabled: false,
105+
is_negative_prompt_avail : false,
106+
negative_prompt : "",
107+
selected_model : 'Default'
97108
};
98109
},
99110
watch: {
@@ -116,7 +127,11 @@ export default {
116127
deep: true
117128
} ,
118129
},
119-
130+
computed:{
131+
this_object(){
132+
return this;
133+
}
134+
},
120135
methods: {
121136
init_state(){
122137
let that = this;
@@ -200,6 +215,19 @@ export default {
200215
this.box_layer = new Konva.Layer();
201216
this.stage.add(this.box_layer);
202217
this.box_layer.add(box);
218+
219+
let tr = new Konva.Transformer({keepRatio : true , rotateEnabled:false , flipEnabled:false, enabledAnchors: ['top-left', 'top-right', 'bottom-left', 'bottom-right'] });
220+
this.box_layer.add(tr);
221+
tr.nodes([box]);
222+
223+
box.on('transform', function () {
224+
box.setAttrs({
225+
width: Math.round(box.width() * box.scaleX()),
226+
height: Math.round(box.height() * box.scaleY()),
227+
scaleX: 1,
228+
scaleY: 1
229+
});
230+
});
203231
204232
this.resize_stage()
205233
@@ -304,7 +332,7 @@ export default {
304332
add_img_to_stage(img_path, is_resizable ){
305333
306334
let that = this;
307-
let scale = that.box.width() / 512 // IMP rn i am assuming that the returned image will be 512x512
335+
let scale = that.box.scaleX()
308336
309337
this.freeze_last_resizable_img()
310338
@@ -315,8 +343,18 @@ export default {
315343
x: that.box.x(),
316344
y: that.box.y(),
317345
scaleX: scale,
318-
scaleY: scale ,
346+
scaleY: scale,
347+
});
348+
349+
350+
if (imgg.width() == imgg.height()){
351+
imgg.setAttrs({
352+
width: that.box.width(),
353+
height: that.box.height(),
319354
});
355+
}
356+
357+
320358
that.images_layer.add(imgg);
321359
322360
let box = new Konva.Rect({
@@ -474,6 +512,9 @@ export default {
474512
this.done_percentage = -1;
475513
this.is_stopping = false;
476514
515+
if(this.is_negative_prompt_avail)
516+
params['negative_prompt'] = this.negative_prompt;
517+
477518
let that = this;
478519
479520
let callbacks = {
@@ -489,6 +530,9 @@ export default {
489530
},
490531
}
491532
533+
if(this.is_negative_prompt_avail)
534+
params['negative_prompt'] = this.negative_prompt;
535+
492536
if(this.stable_diffusion)
493537
this.stable_diffusion.text_to_img(params, callbacks, 'outpainting');
494538

electron_app/src/components_bare/LoaderModal.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
<b-progress v-if="loading_percentage >= 0 " :value="loading_percentage" style="height: 10px;"></b-progress>
1414

1515
<div style="margin-bottom:10px"></div>
16-
<p style="font-variant-numeric: tabular-nums;">{{loading_desc}}</p>
16+
<p style="font-variant-numeric: tabular-nums;margin-bottom: 0px;">{{loading_desc}}
17+
<span v-if="remaining_times"><br>{{remaining_times}}</span>
18+
</p>
1719
</div>
1820

1921
</center>
@@ -24,7 +26,7 @@ import MoonLoader from 'vue-spinner/src/MoonLoader.vue'
2426
2527
export default {
2628
name: 'LoaderModal',
27-
props: ['loading_percentage' ,'loading_desc' , 'loading_title'],
29+
props: ['loading_percentage' ,'loading_desc' , 'loading_title', 'remaining_times'],
2830
components: {MoonLoader},
2931
mounted() {
3032

electron_app/src/components_bare/SDOptionsDropdown.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@
141141
</div>
142142
</span>
143143

144-
144+
<span v-if="!elements_hidden.includes('batch_size')">
145145
<b-form-group inline label="" style="margin-bottom: 6px;">
146-
<span v-if="!elements_hidden.includes('batch_size')">
147146
<div class="options_title">
148147
<div class="options_title_box" style="width: 205px;">
149148
<span>Steps</span>
@@ -162,11 +161,10 @@
162161
required></b-form-select>
163162
</div>
164163
</div>
165-
166-
</span>
167-
168164
</b-form-group>
165+
</span>
169166

167+
<span v-if="!elements_hidden.includes('guidence_scale')">
170168
<b-form-group inline label="" style="margin-bottom: 6px;">
171169
<div style="display: flex;flex-direction: column;width: 300px;">
172170
<div class="options_title_box">
@@ -185,7 +183,9 @@
185183
</div>
186184
</div>
187185
</b-form-group>
186+
</span>
188187

188+
<span v-if="!elements_hidden.includes('seed')">
189189
<div class="options_title">
190190
<div class="options_title_box" style="width: 155px;">
191191
<span>Seed</span>
@@ -210,8 +210,9 @@
210210
placeholder="-1"></b-form-input>
211211
</div>
212212
</div>
213+
</span>
213214

214-
215+
<span v-if="!elements_hidden.includes('custom_model')">
215216
<div class="options_title">
216217
<div class="options_title_box" style="width: 165px;">
217218
<span>Custom Model</span>
@@ -241,6 +242,7 @@
241242
required></b-form-select>
242243
</div>
243244
</div>
245+
</span>
244246

245247
<div class="options_title">
246248
<div class="options_title_box" style="width: 205px;">

electron_app/src/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ function compute_n_cols() {
88
return n_col;
99
}
1010

11-
11+
function compute_time_remaining(time_remaining) {
12+
if (time_remaining.asSeconds() < 1) return "";
13+
if (time_remaining.hours() > 0) return `(${time_remaining.hours()}h${time_remaining.minutes()}m left)`;
14+
else return `(${time_remaining.minutes()}m${time_remaining.seconds()}s left)`;
15+
}
1216

1317
function simple_hash( strr ) {
1418
var hash = 0;
@@ -164,4 +168,4 @@ async function share_on_arthub(imgs , params, prompt ) {
164168

165169

166170

167-
export { compute_n_cols ,resolve_asset_illustration , simple_hash , open_popup, share_on_arthub}
171+
export { compute_n_cols , compute_time_remaining , resolve_asset_illustration , simple_hash , open_popup, share_on_arthub}

0 commit comments

Comments
 (0)