Commit
·
661e2b4
1
Parent(s):
d0f45dd
Add search functionality with semantic and keyword options
Browse files- index.html +44 -12
index.html
CHANGED
|
@@ -95,8 +95,9 @@
|
|
| 95 |
sort: "likes",
|
| 96 |
page: 1,
|
| 97 |
totalPages: -1,
|
| 98 |
-
mode: "light",
|
| 99 |
useTestData: false,
|
|
|
|
|
|
|
| 100 |
buttonClass(attr, filter) {
|
| 101 |
if (this[attr] === filter) {
|
| 102 |
return "text-orange-600 bg-gradient-to-br from-orange-300 to-orange-100 px-2 md:px-3 py-1 rounded-full";
|
|
@@ -110,10 +111,6 @@
|
|
| 110 |
this.themes = data.themes;
|
| 111 |
this.totalPages = data.totalPages;
|
| 112 |
},
|
| 113 |
-
async switchTheme() {
|
| 114 |
-
this.mode = this.mode === "light" ? "dark": "light";
|
| 115 |
-
console.log(this.mode);
|
| 116 |
-
},
|
| 117 |
async sortThemes(sort) {
|
| 118 |
this.sort = sort;
|
| 119 |
this.page = 1;
|
|
@@ -128,6 +125,12 @@
|
|
| 128 |
this.themes = data.themes;
|
| 129 |
this.totalPages = data.totalPages;
|
| 130 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
async getThemes(page, sort, useTestData) {
|
| 132 |
let data;
|
| 133 |
if (useTestData) {
|
|
@@ -137,8 +140,11 @@
|
|
| 137 |
data = await res.json();
|
| 138 |
} else {
|
| 139 |
const searchFilters = this.filter === 'tool' ? 'tool' : '(smolagent OR agent OR smolagents)';
|
|
|
|
|
|
|
|
|
|
| 140 |
const res = await fetch(
|
| 141 |
-
`https://huggingface.co/api/spaces?limit=100&filter=${searchFilters}&expand[]=subdomain&expand[]=lastModified&expand[]=likes&expand[]=runtime`
|
| 142 |
);
|
| 143 |
data = await res.json();
|
| 144 |
console.log(data)
|
|
@@ -185,9 +191,39 @@
|
|
| 185 |
>
|
| 186 |
<section class="container px-6 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-14 mx-auto relative">
|
| 187 |
<div class="col-span-2 lg:col-span-1 flex flex-col gap-14 row-start">
|
| 188 |
-
<
|
|
|
|
|
|
|
|
|
|
| 189 |
</div>
|
| 190 |
<div class="col-span-2 md:col-span-3 flex items-center gap-14 flex flex-wrap lg-auto lg:ml-auto text-sm">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
<div class="flex gap-2">
|
| 192 |
<span class="md:px-3 py-1 text-gray-800">type</span>
|
| 193 |
<button
|
|
@@ -218,10 +254,6 @@
|
|
| 218 |
Recent
|
| 219 |
</button>
|
| 220 |
</div>
|
| 221 |
-
<div class="flex gap-0">
|
| 222 |
-
<input type="checkbox" @click="switchTheme()" class="rounded accent-orange-300">
|
| 223 |
-
<span class="md:px-3 py-1 text-gray-800 ml-0">Show Dark Mode</span>
|
| 224 |
-
</div>
|
| 225 |
</div>
|
| 226 |
</section>
|
| 227 |
<div class="container px-6 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2 mx-auto my-8 relative">
|
|
@@ -230,7 +262,7 @@
|
|
| 230 |
<div class="grid-item-header">
|
| 231 |
<h2 class="text-sm font-medium text-white" x-text="theme.id"></h2>
|
| 232 |
</div>
|
| 233 |
-
<iframe :src="`${theme.subdomain}?_=${new Date().getTime()}
|
| 234 |
<a :href="`https://huggingface.co/spaces/${theme.id}`" target="_blank"></a>
|
| 235 |
</div>
|
| 236 |
</template>
|
|
|
|
| 95 |
sort: "likes",
|
| 96 |
page: 1,
|
| 97 |
totalPages: -1,
|
|
|
|
| 98 |
useTestData: false,
|
| 99 |
+
searchQuery: "",
|
| 100 |
+
searchType: "semantic",
|
| 101 |
buttonClass(attr, filter) {
|
| 102 |
if (this[attr] === filter) {
|
| 103 |
return "text-orange-600 bg-gradient-to-br from-orange-300 to-orange-100 px-2 md:px-3 py-1 rounded-full";
|
|
|
|
| 111 |
this.themes = data.themes;
|
| 112 |
this.totalPages = data.totalPages;
|
| 113 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
async sortThemes(sort) {
|
| 115 |
this.sort = sort;
|
| 116 |
this.page = 1;
|
|
|
|
| 125 |
this.themes = data.themes;
|
| 126 |
this.totalPages = data.totalPages;
|
| 127 |
},
|
| 128 |
+
async searchThemes() {
|
| 129 |
+
this.page = 1;
|
| 130 |
+
const data = await this.getThemes(this.page, this.sort, this.useTestData);
|
| 131 |
+
this.themes = data.themes;
|
| 132 |
+
this.totalPages = data.totalPages;
|
| 133 |
+
},
|
| 134 |
async getThemes(page, sort, useTestData) {
|
| 135 |
let data;
|
| 136 |
if (useTestData) {
|
|
|
|
| 140 |
data = await res.json();
|
| 141 |
} else {
|
| 142 |
const searchFilters = this.filter === 'tool' ? 'tool' : '(smolagent OR agent OR smolagents)';
|
| 143 |
+
const searchParam = this.searchQuery ?
|
| 144 |
+
(this.searchType === 'semantic' ? `&q=${encodeURIComponent(this.searchQuery)}` : `&search=${encodeURIComponent(this.searchQuery)}`)
|
| 145 |
+
: '';
|
| 146 |
const res = await fetch(
|
| 147 |
+
`https://huggingface.co/api/spaces?limit=100&filter=${searchFilters}${searchParam}&expand[]=subdomain&expand[]=lastModified&expand[]=likes&expand[]=runtime`
|
| 148 |
);
|
| 149 |
data = await res.json();
|
| 150 |
console.log(data)
|
|
|
|
| 191 |
>
|
| 192 |
<section class="container px-6 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-14 mx-auto relative">
|
| 193 |
<div class="col-span-2 lg:col-span-1 flex flex-col gap-14 row-start">
|
| 194 |
+
<div class="flex items-center gap-2">
|
| 195 |
+
<img src="https://camo.githubusercontent.com/a8c1f1d12aa3114010c6e74b29d47fee91d8da10a915f065c38e6d0ea7f16568/68747470733a2f2f68756767696e67666163652e636f2f64617461736574732f68756767696e67666163652f646f63756d656e746174696f6e2d696d616765732f7265736f6c76652f6d61696e2f736d6f6c6167656e74732f6d6173636f742e706e67" alt="Smolagents mascot" class="w-14 h-14">
|
| 196 |
+
<h1 class="text-xl font-semibold text-gray-800 whitespace-nowrap">smolagents and tools gallery</h1>
|
| 197 |
+
</div>
|
| 198 |
</div>
|
| 199 |
<div class="col-span-2 md:col-span-3 flex items-center gap-14 flex flex-wrap lg-auto lg:ml-auto text-sm">
|
| 200 |
+
<div class="flex flex-col gap-2">
|
| 201 |
+
<div class="flex items-center">
|
| 202 |
+
<input
|
| 203 |
+
type="text"
|
| 204 |
+
x-model="searchQuery"
|
| 205 |
+
@input="searchThemes()"
|
| 206 |
+
placeholder="Search..."
|
| 207 |
+
class="px-3 py-1 border rounded-l-lg"
|
| 208 |
+
>
|
| 209 |
+
<div class="flex border border-l-0 rounded-r-lg overflow-hidden">
|
| 210 |
+
<button
|
| 211 |
+
@click="searchType = 'semantic'; searchThemes()"
|
| 212 |
+
:class="searchType === 'semantic' ? 'bg-orange-300 text-white' : 'bg-white text-gray-800'"
|
| 213 |
+
class="px-3 py-1"
|
| 214 |
+
>
|
| 215 |
+
Semantic
|
| 216 |
+
</button>
|
| 217 |
+
<button
|
| 218 |
+
@click="searchType = 'keyword'; searchThemes()"
|
| 219 |
+
:class="searchType === 'keyword' ? 'bg-orange-300 text-white' : 'bg-white text-gray-800'"
|
| 220 |
+
class="px-3 py-1 border-l"
|
| 221 |
+
>
|
| 222 |
+
Keyword
|
| 223 |
+
</button>
|
| 224 |
+
</div>
|
| 225 |
+
</div>
|
| 226 |
+
</div>
|
| 227 |
<div class="flex gap-2">
|
| 228 |
<span class="md:px-3 py-1 text-gray-800">type</span>
|
| 229 |
<button
|
|
|
|
| 254 |
Recent
|
| 255 |
</button>
|
| 256 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
</div>
|
| 258 |
</section>
|
| 259 |
<div class="container px-6 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2 mx-auto my-8 relative">
|
|
|
|
| 262 |
<div class="grid-item-header">
|
| 263 |
<h2 class="text-sm font-medium text-white" x-text="theme.id"></h2>
|
| 264 |
</div>
|
| 265 |
+
<iframe :src="`${theme.subdomain}?_=${new Date().getTime()}`" :alt="theme.id" scrolling="no" frameborder="0" loading="lazy"></iframe>
|
| 266 |
<a :href="`https://huggingface.co/spaces/${theme.id}`" target="_blank"></a>
|
| 267 |
</div>
|
| 268 |
</template>
|