Skip to content

Commit 034c276

Browse files
committed
custom model integration done
1 parent dc7914a commit 034c276

File tree

11 files changed

+304
-36
lines changed

11 files changed

+304
-36
lines changed

backends/stable_diffusion_tf/stable_diffusion_tf/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,7 @@
17551755
49407,
17561756
49407,
17571757
]
1758+
17581759
_ALPHAS_CUMPROD = [
17591760
0.99915,
17601761
0.998296,

electron_app/src/App.vue

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
<History :app_state="app_state"></History>
7777
</template>
7878

79+
<template v-slot:settings>
80+
<Settings :app_state="app_state"></Settings>
81+
</template>
82+
7983
<template v-slot:logs>
8084
<div class="animatable_content_box ">
8185
<p>Logs : </p>
@@ -111,6 +115,8 @@ import Outpainting from './components/Outpainting.vue'
111115
import UpscaleImage from './components/UpscaleImage.vue'
112116
import Inpainting from "./components/Inpainting.vue"
113117
import History from './components/History.vue'
118+
import Settings from './components/Settings.vue'
119+
114120
115121
import LoaderModal from './components_bare/LoaderModal.vue'
116122
import Vue from "vue"
@@ -131,7 +137,8 @@ export default
131137
Img2Img,
132138
Outpainting,
133139
UpscaleImage,
134-
Inpainting
140+
Inpainting,
141+
Settings
135142
},
136143
137144
mounted() {
@@ -157,8 +164,19 @@ export default
157164
158165
159166
let data = window.ipcRenderer.sendSync('load_data');
160-
if( data.history)
161-
Vue.set(this.app_state , 'history' , data.history)
167+
if(!data.history){
168+
data.history = {}
169+
}
170+
if(!data.settings){
171+
data.settings = {}
172+
}
173+
if(!data.custom_models){
174+
data.custom_models = {}
175+
}
176+
if( data ){
177+
Vue.set(this.app_state , 'app_data' , data)
178+
}
179+
162180
163181
},
164182
@@ -183,10 +201,10 @@ export default
183201
deep: true
184202
} ,
185203
186-
'app_state.history': {
204+
'app_state.app_data': {
187205
188206
handler: function(new_value) {
189-
window.ipcRenderer.sendSync('save_data', {"history": new_value });
207+
window.ipcRenderer.sendSync('save_data', new_value );
190208
},
191209
deep: true
192210
} ,
@@ -293,7 +311,7 @@ export default
293311
show_splash_screen : true , // is showing the loading splash screen
294312
logs : "",
295313
global_loader_modal_msg : "",
296-
history : {},
314+
app_data: {history : {}},
297315
};
298316
299317
return {

electron_app/src/StableDiffusion.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ export default {
131131
132132
if(prompt_params.negative_prompt){
133133
prompt_params.negative_prompt = remove_non_ascii(prompt_params.negative_prompt)
134-
}
135-
134+
}
136135
137136
this.last_iter_t = Date.now()
138137
this.generated_by = generated_by;

electron_app/src/assets/css/theme.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
@media (prefers-color-scheme: light) {
1414
:root {
15-
--slider-progress: #D0A3FD;
15+
--slider-progress: #8cb8f2;
1616
--slider-progress_end: #F1F4FA;
17-
--slider-circle: #9131F1;
17+
--slider-circle: #3174f1;
1818
--slider-border: white;
1919
}
2020
body {
@@ -136,9 +136,9 @@
136136

137137
@media (prefers-color-scheme: dark) {
138138
:root {
139-
--slider-progress: #5304a3;
139+
--slider-progress: #0444a3;
140140
--slider-progress_end: #303030;
141-
--slider-circle: #3a076d;
141+
--slider-circle: #07296d;
142142
--slider-border: #222222;
143143
}
144144
body {

electron_app/src/components/History.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div @click="toggle_order()" style="float:right; margin-bottom: 20px;" class="l_button">
55
{{this.app_state.show_history_in_oldest_first ? "Oldest": "Newest"}} First
66
</div>
7-
<div v-if="Object.values(app_state.history).length > 0">
7+
<div v-if="Object.values(app_state.app_data.history).length > 0">
88
<div v-for="history_box in get_history()" :key="history_box.key" style="clear: both;">
99

1010
<div @click="delete_hist(history_box.key)" style="float:right; margin-top: 10px;" class="l_button">Delete</div>
@@ -73,11 +73,11 @@ export default {
7373
},
7474
methods: {
7575
delete_hist(k){
76-
Vue.delete( this.app_state.history , k );
76+
Vue.delete( this.app_state.app_data.history , k );
7777
},
7878
7979
get_history() {
80-
let history = Object.values(this.app_state.history);
80+
let history = Object.values(this.app_state.app_data.history);
8181
return this.app_state.show_history_in_oldest_first ? history : history.reverse();
8282
},
8383

electron_app/src/components/Img2Img.vue

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export default {
138138
139139
is_negative_prompt_avail : false,
140140
negative_prompt : "",
141+
selected_model : 'Default'
141142
};
142143
},
143144
methods: {
@@ -180,8 +181,15 @@ export default {
180181
batch_size : this.batch_size ,
181182
img_strength : this.inp_img_strength,
182183
input_image : input_image,
183-
is_inpaint : this.is_inpaint,
184+
is_inpaint : this.is_inpaint
184185
}
186+
187+
if(this.selected_model && this.selected_model != "Default" && this.app_state.app_data.custom_models[this.selected_model] ){
188+
params.model_id = -1;
189+
params.custom_model_path = this.app_state.app_data.custom_models[this.selected_model].path;
190+
}
191+
192+
185193
if(this.is_inpaint)
186194
params['mask_image'] = mask_img;
187195
@@ -199,7 +207,6 @@ export default {
199207
on_img(img_path){
200208
that.generated_images.push(img_path);
201209
202-
203210
let p = {
204211
"prompt":that.prompt , "seed": seed, "key":history_key , "imgs" : [] , "inp_img": input_image_with_mask,
205212
"dif_steps" : that.dif_steps , "inp_img_strength" : that.inp_img_strength, "model_version": that.stable_diffusion.model_version , "guidence_scale" : that.guidence_scale ,
@@ -209,12 +216,12 @@ export default {
209216
if(that.is_negative_prompt_avail)
210217
p['negative_prompt'] = that.negative_prompt;
211218
212-
if(!(that.app_state.history[history_key]))
213-
Vue.set(that.app_state.history, history_key , p );
219+
if(!(that.app_state.app_data.history[history_key]))
220+
Vue.set(that.app_state.app_data.history, history_key , p );
214221
215-
that.app_state.history[history_key].imgs.push(img_path)
222+
that.app_state.app_data.history[history_key].imgs.push(img_path)
216223
217-
console.log(that.app_state.history)
224+
console.log(that.app_state.app_data.history)
218225
219226
},
220227
on_progress(p){

electron_app/src/components/ImgGenerate.vue

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
<div v-if="generated_images.length == 1" >
7474
<center>
75-
<ImageItem :app_state="app_state" :path="generated_images[0]" :style_obj="{ 'width': 'calc(100vh - 380px )' , 'margin-top': '60px' }"></ImageItem>
75+
<ImageItem :app_state="app_state" :path="generated_images[0]" :style_obj="{ 'width': 'calc(100vh - 390px )' , 'margin-top': '60px' }"></ImageItem>
7676
</center>
7777
</div>
7878

@@ -152,6 +152,7 @@ export default {
152152
modifiers : require("../modifiers.json"),
153153
is_negative_prompt_avail : false,
154154
negative_prompt : "",
155+
selected_model : 'Default'
155156
};
156157
157158
},
@@ -179,8 +180,12 @@ export default {
179180
scale : this.guidence_scale ,
180181
ddim_steps : this.dif_steps,
181182
num_imgs : this.num_imgs ,
182-
batch_size : this.batch_size ,
183+
batch_size : this.batch_size
184+
}
183185
186+
if(this.selected_model && this.selected_model != "Default" && this.app_state.app_data.custom_models[this.selected_model] ){
187+
params.model_id = -1;
188+
params.custom_model_path = this.app_state.app_data.custom_models[this.selected_model].path;
184189
}
185190
186191
if(this.is_negative_prompt_avail)
@@ -201,23 +206,23 @@ export default {
201206
on_img(img_path){
202207
that.generated_images.push(img_path);
203208
204-
if(!(that.app_state.history[history_key])){
209+
if(!(that.app_state.app_data.history[history_key])){
205210
let p = {
206211
"prompt":that.prompt , "seed": seed, "img_w":that.img_w , "img_h":that.img_h , "key":history_key , "imgs" : [],
207-
"guidence_scale" : that.guidence_scale , "dif_steps" : that.dif_steps
212+
"guidence_scale" : that.guidence_scale , "dif_steps" : that.dif_steps
208213
}
209214
if(that.stable_diffusion.model_version)
210215
p['model_version'] = that.stable_diffusion.model_version;
211216
if(that.is_negative_prompt_avail)
212217
p['negative_prompt'] = that.negative_prompt;
213-
Vue.set(that.app_state.history, history_key , p);
218+
Vue.set(that.app_state.app_data.history, history_key , p);
214219
}
215220
216221
217222
218-
that.app_state.history[history_key].imgs.push(img_path)
223+
that.app_state.app_data.history[history_key].imgs.push(img_path)
219224
220-
console.log(that.app_state.history)
225+
console.log(that.app_state.app_data.history)
221226
222227
},
223228
on_progress(p ){
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<template>
2+
<div class="animatable_content_box ">
3+
4+
<div v-if="!is_custom_model_loading">
5+
<h1>Settings</h1>
6+
<br>
7+
<h2>General Settings</h2>
8+
9+
<br><hr>
10+
<div class="l_button button_colored" style="float:right" @click="add_model" >Add New Model</div>
11+
<h2>Custom Models</h2>
12+
13+
<!-- <br> -->
14+
<hr>
15+
<div v-for="model in Object.values(this.app_state.app_data.custom_models)" :key="model.name">
16+
<div class="l_button" @click="delete_model(model.name)" style="float:right">Remove</div>
17+
<p> Name : {{model.name}} </p>
18+
<p> Path : {{model.orig_path}} </p>
19+
<hr>
20+
</div>
21+
</div>
22+
<div v-else>
23+
<LoaderModal :loading_percentage="-1" loading_title="Importing model"></LoaderModal>
24+
</div>
25+
26+
</div>
27+
</template>
28+
<script>
29+
import LoaderModal from '../components_bare/LoaderModal.vue'
30+
import Vue from 'vue'
31+
32+
33+
export default {
34+
name: 'Settings',
35+
props: {
36+
app_state : Object ,
37+
},
38+
components: {LoaderModal},
39+
mounted() {
40+
41+
},
42+
data() {
43+
return {
44+
is_custom_model_loading:false,
45+
};
46+
},
47+
methods: {
48+
delete_model(k){
49+
let model_path = this.app_state.app_data.custom_models[k].path;
50+
window.ipcRenderer.sendSync('delete_file', model_path );
51+
Vue.delete( this.app_state.app_data.custom_models , k );
52+
},
53+
add_model(){
54+
let that = this;
55+
56+
let pytorch_model_path = window.ipcRenderer.sendSync('file_dialog', "ckpt_file" );
57+
if(!pytorch_model_path)
58+
return;
59+
60+
if(pytorch_model_path == "NULL")
61+
return;
62+
63+
let model_name = pytorch_model_path.replaceAll("\\" , "/").split("/");
64+
model_name = model_name[model_name.length - 1].split(".")[0]
65+
66+
67+
if(model_name.trim() == ""){
68+
alert("Put non empty model name");
69+
return;
70+
}
71+
72+
if(that.app_state.app_data.custom_models[model_name]){
73+
alert("this model name "+ model_name +" already exists")
74+
return;
75+
}
76+
77+
that.is_custom_model_loading = true
78+
window.ipcRenderer.invoke('add_custom_pytorch_models', pytorch_model_path , model_name ).then((result) => {
79+
that.is_custom_model_loading = false
80+
if(result.success){
81+
Vue.set( that.app_state.app_data.custom_models , model_name , {"name":model_name , "path": result.model_path, "orig_path" : pytorch_model_path } );
82+
} else {
83+
alert("Error " + result.error )
84+
}
85+
86+
})
87+
}
88+
},
89+
}
90+
</script>
91+
<style>
92+
</style>
93+
<style scoped>
94+
</style>

electron_app/src/components_bare/ApplicationFrame.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<font-awesome-icon icon="bars" />
1111
</div>
1212
</template>
13+
1314
<b-dropdown-item-button @click="$emit('menu_item_click_help',{})">Help</b-dropdown-item-button>
1415
<b-dropdown-item-button @click="$emit('menu_item_click_discord',{})">Start Discord Chat</b-dropdown-item-button>
1516
<b-dropdown-item-button @click="selectTab('logs')">Show Logs</b-dropdown-item-button>
@@ -19,6 +20,8 @@
1920

2021
<b-dropdown-item-button @click="$emit('menu_item_click_about',{})">About</b-dropdown-item-button>
2122

23+
<b-dropdown-item-button @click="selectTab('settings')">Settings</b-dropdown-item-button>
24+
2225
<b-dropdown-item-button @click="$emit('menu_item_click_close',{})">Close</b-dropdown-item-button>
2326
<!-- #TODO set these menu items via python -->
2427

@@ -65,13 +68,19 @@
6568
<slot name="outpainting"></slot>
6669
</div>
6770

71+
<div style="display:none" :class="{ bl_display : selected_tab === 'settings' }" >
72+
<slot name="settings"></slot>
73+
</div>
74+
75+
6876

6977

7078
<div v-if="selected_tab === 'logs' " style="display:none" :class="{ bl_display : selected_tab === 'logs' }" >
7179
<slot name="logs"></slot>
7280
</div>
7381

7482

83+
7584

7685

7786

0 commit comments

Comments
 (0)