anzorq commited on
Commit
d16e0f2
β€’
1 Parent(s): 430cd22
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
- let typingInterval;
30
- if (placeholder.length < placeholders[placeholderIndex].length) {
31
- typingInterval = setInterval(() => {
32
- setPlaceholder(prevPlaceholder => prevPlaceholder + placeholders[placeholderIndex][placeholder.length]);
33
- }, 100); // The typing speed
34
- }
35
- return () => clearInterval(typingInterval);
36
- }, [placeholder, placeholderIndex]);
37
 
38
  useEffect(() => {
39
- const indexInterval = setInterval(() => {
40
- if (placeholder === placeholders[placeholderIndex]) {
41
- setPlaceholderIndex(Math.floor(Math.random() * placeholders.length));
42
- setPlaceholder(""); // reset the placeholder when the index changes
 
 
 
43
  }
44
- }, 1500);
 
 
45
 
46
- return () => clearInterval(indexInterval);
47
- }, [placeholder, placeholderIndex]);
 
 
 
 
 
 
 
 
 
 
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 md:w-1/2 h-12 my-8">
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, 90);
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 my-10 ${inter.className}`}>
 
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 && (