Skip to content

Commit 5bd72fb

Browse files
committed
Update StableDiffusion.vue
1 parent 366a447 commit 5bd72fb

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

electron_app/src/StableDiffusion.vue

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
import { send_to_py } from "./py_vue_bridge.js"
77
import {get_tokens} from './clip_tokeniser/clip_encoder.js'
8+
import * as nsfwjs from 'nsfwjs'
89
910
function remove_non_ascii(str) {
1011
@@ -27,6 +28,7 @@ export default {
2728
return {
2829
is_backend_loaded : false,
2930
is_input_avail : false,
31+
nsfw_filter: true,
3032
model_loading_msg : "",
3133
model_loading_title : "",
3234
loading_percentage : -1 ,
@@ -50,11 +52,35 @@ export default {
5052
}
5153
if(msg_code == "nwim"){
5254
let impath = msg.substring(5).trim()
53-
if(this.attached_cbs){
54-
if(this.attached_cbs.on_img)
55-
this.attached_cbs.on_img(impath);
56-
}
5755
56+
const img = new Image();
57+
img.src = "file://" + impath;
58+
59+
img.attached_cbs = this.attached_cbs;
60+
61+
62+
img.onload = () => {
63+
if (this.nsfw_filter == false) {
64+
if (img.attached_cbs) {
65+
if (img.attached_cbs.on_img)
66+
img.attached_cbs.on_img(impath);
67+
}
68+
}
69+
nsfwjs.load()
70+
.then(model => model.classify(img))
71+
.then(predictions => {
72+
switch (predictions[0].className) {
73+
case 'Hentai':
74+
case 'Porn':
75+
case 'Sexy':
76+
impath = "nsfw";
77+
}
78+
if (img.attached_cbs) {
79+
if (img.attached_cbs.on_img)
80+
img.attached_cbs.on_img(impath);
81+
}
82+
});
83+
}
5884
}
5985
6086
if(msg_code == "mdvr"){

0 commit comments

Comments
 (0)