- components/backgroundEmojiGrid.jsx +20 -0
- components/searchBar.jsx +33 -18
- pages/index.js +4 -2
components/backgroundEmojiGrid.jsx
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useEffect, useState } from 'react';
|
2 |
+
|
3 |
+
const emojis = ['π', 'π', 'π', 'π¨βπ»', 'π©βπ»', 'π', 'π₯', 'π', 'π', 'π', 'π', 'π€©', 'π₯³', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π³', 'π²', 'π±', 'π£', 'π€', 'π¦', 'π©', 'πͺ', 'π', 'π°', 'π«', 'π¬', 'π', 'πΏ', 'π·', 'πΈ', 'πΉ', 'πΊ', 'π»', 'π½', 'π₯’', 'π§', 'β½οΈ', 'π', 'π', 'βΎοΈ', 'πΎ', 'π', 'π', 'π±', 'π', 'πΈ', 'π', 'π', 'π₯', 'π', 'π₯
', 'β³οΈ', 'πΉ', 'π£', 'π₯', 'π₯', 'π½', 'πΉ', 'π·', 'π₯', 'πΏ', 'β·', 'π', 'ποΈββοΈ', 'π€ΌββοΈ', 'π€ΈββοΈ', 'βΉοΈββοΈ', 'π€Ί', 'π€ΎββοΈ', 'ποΈββοΈ', 'π', 'π§ββοΈ', 'πββοΈ', 'πββοΈ', 'π€½ββοΈ', 'π£ββοΈ', 'π§ββοΈ', 'π΅ββοΈ', 'π΄ββοΈ', 'π', 'π»']
|
4 |
+
|
5 |
+
export default function BackgroundEmojiGrid() {
|
6 |
+
const [grid, setGrid] = useState([]);
|
7 |
+
|
8 |
+
useEffect(() => {
|
9 |
+
const newGrid = Array.from({ length: 1000 }, () => emojis[Math.floor(Math.random() * emojis.length)]); // Adjust the length to suit the size of your grid
|
10 |
+
setGrid(newGrid);
|
11 |
+
}, []);
|
12 |
+
|
13 |
+
return (
|
14 |
+
<div className="fixed top-1/2 left-1/2 w-[200vh] h-[200vh] overflow-hidden -z-10 transform -translate-x-1/2 -translate-y-1/2 rotate-45 opacity-10">
|
15 |
+
{grid.map((emoji, i) => (
|
16 |
+
<span key={i} className="inline-block w-24 h-24 md:w-32 md:h-32 text-4xl">{emoji}</span> // Adjust the width and height to suit the size of your grid cells
|
17 |
+
))}
|
18 |
+
</div>
|
19 |
+
);
|
20 |
+
}
|
components/searchBar.jsx
CHANGED
@@ -4,6 +4,8 @@ const SearchBar = ({ onSearch }) => {
|
|
4 |
const [query, setQuery] = useState("");
|
5 |
const [placeholderIndex, setPlaceholderIndex] = useState(0);
|
6 |
const [placeholder, setPlaceholder] = useState("");
|
|
|
|
|
7 |
const placeholders = [
|
8 |
"Generate music",
|
9 |
"Remove background from images",
|
@@ -26,25 +28,38 @@ const SearchBar = ({ onSearch }) => {
|
|
26 |
];
|
27 |
|
28 |
useEffect(() => {
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
return () => clearInterval(typingInterval);
|
36 |
-
}, [placeholder, placeholderIndex]);
|
37 |
|
38 |
useEffect(() => {
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
43 |
}
|
44 |
-
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
const handleKeyDown = (event) => {
|
50 |
if (event.key === "Enter") {
|
@@ -53,10 +68,10 @@ const SearchBar = ({ onSearch }) => {
|
|
53 |
};
|
54 |
|
55 |
return (
|
56 |
-
<div className="flex items-center justify-center bg-gray-900 rounded-xl shadow-sm
|
57 |
<input
|
58 |
type="text"
|
59 |
-
placeholder={placeholder}
|
60 |
className="search-bar w-full h-full px-4 py-2 text-gray-200 bg-gray-800 border border-gray-700 rounded-xl shadow-sm appearance-none focus:outline-none focus:ring-2"
|
61 |
value={query}
|
62 |
onChange={(e) => setQuery(e.target.value)}
|
@@ -66,4 +81,4 @@ const SearchBar = ({ onSearch }) => {
|
|
66 |
);
|
67 |
};
|
68 |
|
69 |
-
export default SearchBar;
|
|
|
4 |
const [query, setQuery] = useState("");
|
5 |
const [placeholderIndex, setPlaceholderIndex] = useState(0);
|
6 |
const [placeholder, setPlaceholder] = useState("");
|
7 |
+
const [showInitialPlaceholder, setShowInitialPlaceholder] = useState(true);
|
8 |
+
const initialPlaceholder = "Discover thousands of spaces";
|
9 |
const placeholders = [
|
10 |
"Generate music",
|
11 |
"Remove background from images",
|
|
|
28 |
];
|
29 |
|
30 |
useEffect(() => {
|
31 |
+
const initialTimeout = setTimeout(() => {
|
32 |
+
setShowInitialPlaceholder(false);
|
33 |
+
}, 4000);
|
34 |
+
|
35 |
+
return () => clearTimeout(initialTimeout);
|
36 |
+
}, []);
|
|
|
|
|
37 |
|
38 |
useEffect(() => {
|
39 |
+
if (!showInitialPlaceholder) {
|
40 |
+
let typingInterval;
|
41 |
+
if (placeholder.length < placeholders[placeholderIndex].length) {
|
42 |
+
const typingSpeed = Math.floor(Math.random() * 101) + 100;
|
43 |
+
typingInterval = setInterval(() => {
|
44 |
+
setPlaceholder(prevPlaceholder => prevPlaceholder + placeholders[placeholderIndex][placeholder.length]);
|
45 |
+
}, typingSpeed);
|
46 |
}
|
47 |
+
return () => clearInterval(typingInterval);
|
48 |
+
}
|
49 |
+
}, [placeholder, placeholderIndex, showInitialPlaceholder]);
|
50 |
|
51 |
+
useEffect(() => {
|
52 |
+
if (!showInitialPlaceholder) {
|
53 |
+
const indexInterval = setInterval(() => {
|
54 |
+
if (placeholder === placeholders[placeholderIndex]) {
|
55 |
+
setPlaceholderIndex(Math.floor(Math.random() * placeholders.length));
|
56 |
+
setPlaceholder(""); // reset the placeholder when the index changes
|
57 |
+
}
|
58 |
+
}, 1500);
|
59 |
+
|
60 |
+
return () => clearInterval(indexInterval);
|
61 |
+
}
|
62 |
+
}, [placeholder, placeholderIndex, showInitialPlaceholder]);
|
63 |
|
64 |
const handleKeyDown = (event) => {
|
65 |
if (event.key === "Enter") {
|
|
|
68 |
};
|
69 |
|
70 |
return (
|
71 |
+
<div className="flex items-center justify-center bg-gray-900 rounded-xl shadow-sm w-full lg:w-1/2 h-12 my-8">
|
72 |
<input
|
73 |
type="text"
|
74 |
+
placeholder={showInitialPlaceholder ? initialPlaceholder : placeholder}
|
75 |
className="search-bar w-full h-full px-4 py-2 text-gray-200 bg-gray-800 border border-gray-700 rounded-xl shadow-sm appearance-none focus:outline-none focus:ring-2"
|
76 |
value={query}
|
77 |
onChange={(e) => setQuery(e.target.value)}
|
|
|
81 |
);
|
82 |
};
|
83 |
|
84 |
+
export default SearchBar;
|
pages/index.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import { Inter } from 'next/font/google';
|
2 |
import SearchBar from '@/components/searchBar';
|
3 |
import Card from '@/components/card';
|
|
|
4 |
import { predict } from '@/pages/api/api_hf';
|
5 |
import { get_space_info } from '@/pages/api/hf_space';
|
6 |
import { useState, useEffect } from 'react';
|
@@ -42,7 +43,7 @@ export default function Home() {
|
|
42 |
setSearchResults([]);
|
43 |
return;
|
44 |
}
|
45 |
-
const results = await predict(query,
|
46 |
setSearchResults(results);
|
47 |
}
|
48 |
|
@@ -55,7 +56,8 @@ export default function Home() {
|
|
55 |
}, []);
|
56 |
|
57 |
return (
|
58 |
-
<main className={`flex min-h-screen flex-col items-center p-8 md:px-24
|
|
|
59 |
<h1 className="text-4xl md:text-6xl font-bold text-center mb-12">π€ Hugging Face Spaces</h1>
|
60 |
<SearchBar onSearch={onSearch} />
|
61 |
{spaceInfo !== null && (
|
|
|
1 |
import { Inter } from 'next/font/google';
|
2 |
import SearchBar from '@/components/searchBar';
|
3 |
import Card from '@/components/card';
|
4 |
+
import BackgroundEmojiGrid from '@/components/backgroundEmojiGrid';
|
5 |
import { predict } from '@/pages/api/api_hf';
|
6 |
import { get_space_info } from '@/pages/api/hf_space';
|
7 |
import { useState, useEffect } from 'react';
|
|
|
43 |
setSearchResults([]);
|
44 |
return;
|
45 |
}
|
46 |
+
const results = await predict(query, 10);
|
47 |
setSearchResults(results);
|
48 |
}
|
49 |
|
|
|
56 |
}, []);
|
57 |
|
58 |
return (
|
59 |
+
<main className={`flex min-h-screen flex-col items-center p-8 md:px-24 py-20 bg-gray-950 ${inter.className}`}>
|
60 |
+
{/* <BackgroundEmojiGrid /> */}
|
61 |
<h1 className="text-4xl md:text-6xl font-bold text-center mb-12">π€ Hugging Face Spaces</h1>
|
62 |
<SearchBar onSearch={onSearch} />
|
63 |
{spaceInfo !== null && (
|