Spaces:
Running
Running
filter by hardware
Browse files- app/page.tsx +1 -9
- components/spaces/index.tsx +29 -26
- components/spaces/space.tsx +2 -1
- utils/index.ts +4 -3
app/page.tsx
CHANGED
|
@@ -20,13 +20,5 @@ export default async function Home({
|
|
| 20 |
searchParams: { sort: string };
|
| 21 |
}) {
|
| 22 |
const spaces = await getSpaces(sort);
|
| 23 |
-
return
|
| 24 |
-
<section className="flex h-screen overflow-auto">
|
| 25 |
-
<div className="w-full container px-6 py-10 lg:py-20 mx-auto space-y-10 lg:space-y-14">
|
| 26 |
-
<Suspense fallback={<div>Loading...</div>}>
|
| 27 |
-
<Spaces spaces={spaces} />
|
| 28 |
-
</Suspense>
|
| 29 |
-
</div>
|
| 30 |
-
</section>
|
| 31 |
-
);
|
| 32 |
}
|
|
|
|
| 20 |
searchParams: { sort: string };
|
| 21 |
}) {
|
| 22 |
const spaces = await getSpaces(sort);
|
| 23 |
+
return <Spaces spaces={spaces} />;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
components/spaces/index.tsx
CHANGED
|
@@ -1,18 +1,19 @@
|
|
| 1 |
"use client";
|
| 2 |
import { useState } from "react";
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import { SpaceProps } from "@/utils/type";
|
| 5 |
import { SpaceIcon } from "@/components/space_icon";
|
| 6 |
|
| 7 |
import { Space } from "@/components/spaces/space";
|
| 8 |
import { Sort } from "@/components/sort";
|
| 9 |
-
import { useUpdateEffect } from "react-use";
|
| 10 |
-
import { useRouter } from "next/navigation";
|
| 11 |
|
| 12 |
export const Spaces: React.FC<{ spaces: SpaceProps[] }> = ({ spaces }) => {
|
| 13 |
const [selectedGpu, setSelectedGpu] = useState<string | undefined>(undefined);
|
| 14 |
const router = useRouter();
|
| 15 |
const [sort, setSort] = useState<"likes" | "createdAt">("likes");
|
|
|
|
| 16 |
|
| 17 |
useUpdateEffect(() => {
|
| 18 |
router.push("/?sort=" + sort);
|
|
@@ -27,32 +28,34 @@ export const Spaces: React.FC<{ spaces: SpaceProps[] }> = ({ spaces }) => {
|
|
| 27 |
};
|
| 28 |
|
| 29 |
return (
|
| 30 |
-
|
| 31 |
-
<
|
| 32 |
-
<
|
| 33 |
-
<div
|
| 34 |
-
<
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
</div>
|
| 37 |
-
<
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
</div>
|
| 44 |
-
<Sort value={sort} onChange={setSort} />
|
| 45 |
-
</header>
|
| 46 |
-
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
|
| 47 |
-
{spaces?.map((space: SpaceProps) => (
|
| 48 |
-
<Space
|
| 49 |
-
key={space.id}
|
| 50 |
-
space={space}
|
| 51 |
-
selected={selectedGpu === space.id}
|
| 52 |
-
onSelect={handleSelectGpu}
|
| 53 |
-
/>
|
| 54 |
-
))}
|
| 55 |
</div>
|
| 56 |
-
|
| 57 |
);
|
| 58 |
};
|
|
|
|
| 1 |
"use client";
|
| 2 |
import { useState } from "react";
|
| 3 |
+
import { useUpdateEffect } from "react-use";
|
| 4 |
+
import { useRouter } from "next/navigation";
|
| 5 |
|
| 6 |
import { SpaceProps } from "@/utils/type";
|
| 7 |
import { SpaceIcon } from "@/components/space_icon";
|
| 8 |
|
| 9 |
import { Space } from "@/components/spaces/space";
|
| 10 |
import { Sort } from "@/components/sort";
|
|
|
|
|
|
|
| 11 |
|
| 12 |
export const Spaces: React.FC<{ spaces: SpaceProps[] }> = ({ spaces }) => {
|
| 13 |
const [selectedGpu, setSelectedGpu] = useState<string | undefined>(undefined);
|
| 14 |
const router = useRouter();
|
| 15 |
const [sort, setSort] = useState<"likes" | "createdAt">("likes");
|
| 16 |
+
const [elementsInView, setElementsInView] = useState<string[]>([]);
|
| 17 |
|
| 18 |
useUpdateEffect(() => {
|
| 19 |
router.push("/?sort=" + sort);
|
|
|
|
| 28 |
};
|
| 29 |
|
| 30 |
return (
|
| 31 |
+
<section className="flex h-screen overflow-auto">
|
| 32 |
+
<div className="w-full container px-6 py-10 lg:py-20 mx-auto space-y-10 lg:space-y-14">
|
| 33 |
+
<header className="max-w-5xl mx-auto w-full max-lg:flex-col items-start flex lg:items-end lg:justify-between gap-4">
|
| 34 |
+
<div>
|
| 35 |
+
<div className="mb-6 font-regular text-xs text-center max-w-max rounded-full border-gray-200 bg-gray-50 border text-gray-700 px-3 py-2 transition-all duration-300">
|
| 36 |
+
<SpaceIcon className="inline-block w-4 h-4 mr-2 drop-shadow-lg" />
|
| 37 |
+
Browse {spaces.length} spaces
|
| 38 |
+
</div>
|
| 39 |
+
<h1 className="font-extrabold text-3xl text-black">
|
| 40 |
+
Zero GPU Spaces
|
| 41 |
+
</h1>
|
| 42 |
+
<p className="text-neutral-500 font-regular text-base">
|
| 43 |
+
Discover spaces with zero GPU usage on 🤗 Hugging Face Spaces.
|
| 44 |
+
</p>
|
| 45 |
</div>
|
| 46 |
+
<Sort value={sort} onChange={setSort} />
|
| 47 |
+
</header>
|
| 48 |
+
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 pb-10">
|
| 49 |
+
{spaces?.map((space: SpaceProps) => (
|
| 50 |
+
<Space
|
| 51 |
+
key={space.id}
|
| 52 |
+
space={space}
|
| 53 |
+
selected={selectedGpu === space.id}
|
| 54 |
+
onSelect={handleSelectGpu}
|
| 55 |
+
/>
|
| 56 |
+
))}
|
| 57 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
</div>
|
| 59 |
+
</section>
|
| 60 |
);
|
| 61 |
};
|
components/spaces/space.tsx
CHANGED
|
@@ -18,7 +18,8 @@ export const Space: React.FC<Props> = ({ space, selected, onSelect }) => {
|
|
| 18 |
<Link
|
| 19 |
href={`https://huggingface.co/spaces/${space.id}`}
|
| 20 |
target="_blank"
|
| 21 |
-
className="relative hover:z-40 bg-gray-50 border border-gray-200 px-6 py-4 rounded-xl transition-all duration-300 hover:-translate-y-1.5 hover:border-amber-400 hover:shadow-xl hover:shadow-black/5 group"
|
|
|
|
| 22 |
onMouseEnter={() => onSelect?.(space.id)}
|
| 23 |
onMouseLeave={() => onSelect?.(space.id)}
|
| 24 |
>
|
|
|
|
| 18 |
<Link
|
| 19 |
href={`https://huggingface.co/spaces/${space.id}`}
|
| 20 |
target="_blank"
|
| 21 |
+
className="space relative hover:z-40 bg-gray-50 border border-gray-200 px-6 py-4 rounded-xl transition-all duration-300 hover:-translate-y-1.5 hover:border-amber-400 hover:shadow-xl hover:shadow-black/5 group"
|
| 22 |
+
data-space-id={space.id}
|
| 23 |
onMouseEnter={() => onSelect?.(space.id)}
|
| 24 |
onMouseLeave={() => onSelect?.(space.id)}
|
| 25 |
>
|
utils/index.ts
CHANGED
|
@@ -3,15 +3,16 @@ import { SpaceProps } from "./type";
|
|
| 3 |
export const fetchAllPages = async (sort = "trending") => {
|
| 4 |
const filter_key = "zero-a10g";
|
| 5 |
|
| 6 |
-
const pageNumbers = Array.from({ length:
|
| 7 |
const urls = pageNumbers.map(async (pageNumber) => {
|
| 8 |
-
const url = `https://huggingface.co/spaces-json?p=${pageNumber}&sort=${sort}`;
|
| 9 |
const response = await fetch(url);
|
| 10 |
const json = await response.json();
|
| 11 |
return json?.spaces ?? [];
|
| 12 |
});
|
|
|
|
| 13 |
const jsonResponses = await Promise.all(urls);
|
| 14 |
-
const spaces = jsonResponses.flat()
|
| 15 |
return spaces;
|
| 16 |
};
|
| 17 |
|
|
|
|
| 3 |
export const fetchAllPages = async (sort = "trending") => {
|
| 4 |
const filter_key = "zero-a10g";
|
| 5 |
|
| 6 |
+
const pageNumbers = Array.from({ length: 55 }, (_, i) => i);
|
| 7 |
const urls = pageNumbers.map(async (pageNumber) => {
|
| 8 |
+
const url = `https://huggingface.co/spaces-json?p=${pageNumber}&sort=${sort}&runtime.hardware.current=${filter_key}`;
|
| 9 |
const response = await fetch(url);
|
| 10 |
const json = await response.json();
|
| 11 |
return json?.spaces ?? [];
|
| 12 |
});
|
| 13 |
+
|
| 14 |
const jsonResponses = await Promise.all(urls);
|
| 15 |
+
const spaces = jsonResponses.flat();
|
| 16 |
return spaces;
|
| 17 |
};
|
| 18 |
|