Spaces:
Running
Running
filter all nsfw
Browse files- index.html +34 -61
index.html
CHANGED
@@ -46,22 +46,7 @@
|
|
46 |
Alpine.data("modelsData", () => ({
|
47 |
async init() {
|
48 |
const data = await this.getModels(this.page, this.sort);
|
49 |
-
this.models = data.models
|
50 |
-
id: model.id,
|
51 |
-
likes: model.likes,
|
52 |
-
class: model.class,
|
53 |
-
//"anime"
|
54 |
-
//"3d"
|
55 |
-
//"other"
|
56 |
-
//"real_life"
|
57 |
-
//"manga_like"
|
58 |
-
//"aesthetic"
|
59 |
-
//"not_aesthetic"
|
60 |
-
//"safe"
|
61 |
-
//"suggestive"
|
62 |
-
//"explicit"
|
63 |
-
images: model.images.filter((image) => image && image.endsWith(".jpg")),
|
64 |
-
}));
|
65 |
this.totalPages = data.totalPages;
|
66 |
},
|
67 |
ASSETS_URL: "https://d26smi9133w0oo.cloudfront.net/diffusers-gallery/",
|
@@ -70,18 +55,6 @@
|
|
70 |
sort: "trending",
|
71 |
page: 1,
|
72 |
totalPages: -1,
|
73 |
-
isNSFW(model) {
|
74 |
-
if ("class" in model) {
|
75 |
-
// check if class is empty object
|
76 |
-
if (Object.keys(model.class).length === 0) {
|
77 |
-
return ""
|
78 |
-
}
|
79 |
-
if (model.class.explicit > 0.1 || model.class.suggestive > 0.4) {
|
80 |
-
return "blur-md"
|
81 |
-
}
|
82 |
-
}
|
83 |
-
return ""
|
84 |
-
},
|
85 |
buttonClass(attr, filter) {
|
86 |
if (this[attr] === filter) {
|
87 |
return "bg-black shadow-lg text-white"
|
@@ -91,48 +64,48 @@
|
|
91 |
filterModels() {
|
92 |
switch (this.filter) {
|
93 |
case "all":
|
94 |
-
return this.models
|
95 |
case "anime":
|
96 |
-
return this.models.filter((model) => model.class.anime > 0.1)
|
97 |
case "3d":
|
98 |
-
return this.models.filter((model) => model.class["3d"] > 0.1)
|
99 |
case "realistic":
|
100 |
-
return this.models.filter((model) => model.class.real_life > 0.1)
|
|
|
|
|
101 |
}
|
102 |
return []
|
103 |
},
|
104 |
-
sortModels(sort) {
|
105 |
this.sort = sort
|
106 |
this.page = 1
|
107 |
-
this.getModels(this.page, this.sort)
|
108 |
-
|
109 |
-
|
110 |
-
likes: model.likes,
|
111 |
-
class: model.class,
|
112 |
-
images: model.images.filter((image) => image && image.endsWith(".jpg")),
|
113 |
-
}));
|
114 |
-
this.models = models;
|
115 |
-
});
|
116 |
-
|
117 |
},
|
118 |
-
getModels(page, sort) {
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
},
|
124 |
-
nextPage() {
|
125 |
if (this.page < this.totalPages) {
|
126 |
this.page += 1;
|
127 |
-
this.getModels(this.page, this.sort)
|
128 |
-
|
129 |
-
|
130 |
-
likes: model.likes,
|
131 |
-
class: model.class,
|
132 |
-
images: model.images.filter((image) => image && image.endsWith(".jpg")),
|
133 |
-
}));
|
134 |
-
this.models = this.models.concat(models);
|
135 |
-
});
|
136 |
}
|
137 |
},
|
138 |
}));
|
@@ -173,9 +146,9 @@
|
|
173 |
<button :class="buttonClass('filter', 'realistic')"
|
174 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
175 |
@click="filter='realistic'">Realistic</button>
|
176 |
-
<button :class="buttonClass('filter', '
|
177 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
178 |
-
@click="filter='
|
179 |
</div>
|
180 |
</div>
|
181 |
|
@@ -198,7 +171,7 @@
|
|
198 |
<div x-text="model.id"
|
199 |
class="text-base md:text-lg lg:text-xl font-semibold group-hover:translate-x-0.5 transition"></div>
|
200 |
</div>
|
201 |
-
<div class="group-hover:brightness-90 h-full" :class="isNSFW
|
202 |
<template x-if="model.images[0]">
|
203 |
<img :src="()=> ASSETS_URL + model.images[0]" :alt="model.id" alt=""
|
204 |
class="w-full h-full object-cover group-hover:scale-[1.01] transition" />
|
|
|
46 |
Alpine.data("modelsData", () => ({
|
47 |
async init() {
|
48 |
const data = await this.getModels(this.page, this.sort);
|
49 |
+
this.models = data.models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
this.totalPages = data.totalPages;
|
51 |
},
|
52 |
ASSETS_URL: "https://d26smi9133w0oo.cloudfront.net/diffusers-gallery/",
|
|
|
55 |
sort: "trending",
|
56 |
page: 1,
|
57 |
totalPages: -1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
buttonClass(attr, filter) {
|
59 |
if (this[attr] === filter) {
|
60 |
return "bg-black shadow-lg text-white"
|
|
|
64 |
filterModels() {
|
65 |
switch (this.filter) {
|
66 |
case "all":
|
67 |
+
return this.models.filter((model) => !model.isNSFW)
|
68 |
case "anime":
|
69 |
+
return this.models.filter((model) => model.class.anime > 0.1 && !model.isNSFW)
|
70 |
case "3d":
|
71 |
+
return this.models.filter((model) => model.class["3d"] > 0.1 && !model.isNSFW)
|
72 |
case "realistic":
|
73 |
+
return this.models.filter((model) => model.class.real_life > 0.1 && !model.isNSFW)
|
74 |
+
case "18+":
|
75 |
+
return this.models.filter((model) => model.isNSFW)
|
76 |
}
|
77 |
return []
|
78 |
},
|
79 |
+
async sortModels(sort) {
|
80 |
this.sort = sort
|
81 |
this.page = 1
|
82 |
+
const data = await this.getModels(this.page, this.sort)
|
83 |
+
this.models = data.models;
|
84 |
+
this.totalPages = data.totalPages;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
},
|
86 |
+
async getModels(page, sort) {
|
87 |
+
const res = await fetch(`http://localhost:8000/api/models?page=${page}&sort=${sort}`)
|
88 |
+
// return fetch(`https://huggingface-projects-diffusers-gallery-bot.hf.space/api/models?page=${page}&sort=${sort}`).then(
|
89 |
+
const data = await res.json();
|
90 |
+
const models = data.models.map((model) => ({
|
91 |
+
id: model.id,
|
92 |
+
likes: model.likes,
|
93 |
+
class: model.class,
|
94 |
+
isNSFW: model.class.explicit > 0.3 || model.class.suggestive > 0.3,
|
95 |
+
images: model.images.filter((image) => image && image.endsWith(".jpg")),
|
96 |
+
}));
|
97 |
+
|
98 |
+
return {
|
99 |
+
models,
|
100 |
+
totalPages: data.totalPages
|
101 |
+
}
|
102 |
},
|
103 |
+
async nextPage() {
|
104 |
if (this.page < this.totalPages) {
|
105 |
this.page += 1;
|
106 |
+
const data = await this.getModels(this.page, this.sort);
|
107 |
+
this.models = this.models.concat(data.models);
|
108 |
+
this.totalPages = data.totalPages;
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
},
|
111 |
}));
|
|
|
146 |
<button :class="buttonClass('filter', 'realistic')"
|
147 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
148 |
@click="filter='realistic'">Realistic</button>
|
149 |
+
<button :class="buttonClass('filter', '18+')"
|
150 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
151 |
+
@click="filter='18+'">18+</button>
|
152 |
</div>
|
153 |
</div>
|
154 |
|
|
|
171 |
<div x-text="model.id"
|
172 |
class="text-base md:text-lg lg:text-xl font-semibold group-hover:translate-x-0.5 transition"></div>
|
173 |
</div>
|
174 |
+
<div class="group-hover:brightness-90 h-full" :class="model.isNSFW ? 'blur-md' : ''">
|
175 |
<template x-if="model.images[0]">
|
176 |
<img :src="()=> ASSETS_URL + model.images[0]" :alt="model.id" alt=""
|
177 |
class="w-full h-full object-cover group-hover:scale-[1.01] transition" />
|