move filter to backend
Browse files- index.html +21 -29
index.html
CHANGED
@@ -45,7 +45,7 @@
|
|
45 |
|
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 |
},
|
@@ -61,37 +61,29 @@
|
|
61 |
}
|
62 |
return "text-gray-600 hover:bg-gray-200 hover:text-gray-800"
|
63 |
},
|
64 |
-
filterModels() {
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
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 |
-
|
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 |
-
|
95 |
images: model.images.filter((image) => image && image.endsWith(".jpg")),
|
96 |
}));
|
97 |
|
@@ -103,7 +95,7 @@
|
|
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 |
}
|
@@ -136,23 +128,23 @@
|
|
136 |
<div class="flex text-xs gap-2">
|
137 |
<span class="px-2 md:px-3 py-1 font-thin"> style</span>
|
138 |
<button :class="buttonClass('filter', 'all')" class="px-2 md:px-3 py-1 rounded-full"
|
139 |
-
@click="
|
140 |
<button :class="buttonClass('filter', 'anime')"
|
141 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
142 |
-
@click="
|
143 |
<button :class="buttonClass('filter', '3d')"
|
144 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
145 |
-
@click="
|
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="
|
149 |
-
<button :class="buttonClass('filter', '
|
150 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
151 |
-
@click="
|
152 |
</div>
|
153 |
</div>
|
154 |
|
155 |
-
<template x-for="model in
|
156 |
<template x-if="model.images.length > 0">
|
157 |
<a :href="`https://huggingface.co/${model.id}`"
|
158 |
class="block bg-gray-900 rounded-xl overflow-hidden relative group aspect-square text-white" target="_blank">
|
@@ -171,7 +163,7 @@
|
|
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.
|
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" />
|
|
|
45 |
|
46 |
Alpine.data("modelsData", () => ({
|
47 |
async init() {
|
48 |
+
const data = await this.getModels(this.page, this.sort, this.filter);
|
49 |
this.models = data.models
|
50 |
this.totalPages = data.totalPages;
|
51 |
},
|
|
|
61 |
}
|
62 |
return "text-gray-600 hover:bg-gray-200 hover:text-gray-800"
|
63 |
},
|
64 |
+
async filterModels(style) {
|
65 |
+
this.filter = style
|
66 |
+
this.page = 1
|
67 |
+
const data = await this.getModels(this.page, this.sort, this.filter)
|
68 |
+
this.models = data.models
|
69 |
+
this.totalPages = data.totalPages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
},
|
71 |
async sortModels(sort) {
|
72 |
this.sort = sort
|
73 |
this.page = 1
|
74 |
+
const data = await this.getModels(this.page, this.sort, this.filter);
|
75 |
this.models = data.models;
|
76 |
this.totalPages = data.totalPages;
|
77 |
},
|
78 |
+
async getModels(page, sort, style) {
|
79 |
+
// const res = await fetch(`http://localhost:8000/api/models?page=${page}&sort=${sort}&style=${style}`)
|
80 |
+
const res = await fetch(`https://huggingface-projects-diffusers-gallery-bot.hf.space/api/models?page=${page}&sort=${sort}&style=${style}`);
|
81 |
const data = await res.json();
|
82 |
const models = data.models.map((model) => ({
|
83 |
id: model.id,
|
84 |
likes: model.likes,
|
85 |
class: model.class,
|
86 |
+
isNFSW: model.isNFSW,
|
87 |
images: model.images.filter((image) => image && image.endsWith(".jpg")),
|
88 |
}));
|
89 |
|
|
|
95 |
async nextPage() {
|
96 |
if (this.page < this.totalPages) {
|
97 |
this.page += 1;
|
98 |
+
const data = await this.getModels(this.page, this.sort, this.filter);
|
99 |
this.models = this.models.concat(data.models);
|
100 |
this.totalPages = data.totalPages;
|
101 |
}
|
|
|
128 |
<div class="flex text-xs gap-2">
|
129 |
<span class="px-2 md:px-3 py-1 font-thin"> style</span>
|
130 |
<button :class="buttonClass('filter', 'all')" class="px-2 md:px-3 py-1 rounded-full"
|
131 |
+
@click="filterModels('all')">All</button>
|
132 |
<button :class="buttonClass('filter', 'anime')"
|
133 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
134 |
+
@click="filterModels('anime')">Anime</button>
|
135 |
<button :class="buttonClass('filter', '3d')"
|
136 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
137 |
+
@click="filterModels('3d')">3D</button>
|
138 |
<button :class="buttonClass('filter', 'realistic')"
|
139 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
140 |
+
@click="filterModels('realistic')">Realistic</button>
|
141 |
+
<button :class="buttonClass('filter', 'nsfw')"
|
142 |
class="text-gray-600 hover:bg-gray-200 hover:text-gray-800 px-2 md:px-3 py-1 rounded-full"
|
143 |
+
@click="filterModels('nsfw')">18+</button>
|
144 |
</div>
|
145 |
</div>
|
146 |
|
147 |
+
<template x-for="model in models" :key="model.id">
|
148 |
<template x-if="model.images.length > 0">
|
149 |
<a :href="`https://huggingface.co/${model.id}`"
|
150 |
class="block bg-gray-900 rounded-xl overflow-hidden relative group aspect-square text-white" target="_blank">
|
|
|
163 |
<div x-text="model.id"
|
164 |
class="text-base md:text-lg lg:text-xl font-semibold group-hover:translate-x-0.5 transition"></div>
|
165 |
</div>
|
166 |
+
<div class="group-hover:brightness-90 h-full" :class="model.isNFSW ? 'blur-md' : ''">
|
167 |
<template x-if="model.images[0]">
|
168 |
<img :src="()=> ASSETS_URL + model.images[0]" :alt="model.id" alt=""
|
169 |
class="w-full h-full object-cover group-hover:scale-[1.01] transition" />
|