Spaces:
Running
Running
File size: 15,536 Bytes
e055fb3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Recommendation Tool</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.book-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}
.loading-spinner {
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<header class="text-center mb-12">
<h1 class="text-4xl md:text-5xl font-bold text-indigo-800 mb-4">BookMatch</h1>
<p class="text-lg text-gray-600 max-w-2xl mx-auto">
Discover your next favorite book based on your preferences, mood, or reading history.
</p>
</header>
<!-- Main Content -->
<main>
<!-- Search Section -->
<section class="bg-white rounded-xl shadow-lg p-6 mb-12 max-w-3xl mx-auto">
<h2 class="text-2xl font-semibold text-gray-800 mb-6">What are you in the mood to read?</h2>
<div class="mb-6">
<label for="userInput" class="block text-sm font-medium text-gray-700 mb-2">
Tell us about your reading preferences:
</label>
<textarea
id="userInput"
rows="5"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition"
placeholder="e.g. 'I love mystery novels with strong female protagonists' or 'Looking for sci-fi books similar to Dune'"></textarea>
</div>
<div class="flex flex-col sm:flex-row gap-4">
<div class="flex-1">
<label for="genre" class="block text-sm font-medium text-gray-700 mb-2">Preferred Genre</label>
<select id="genre" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
<option value="">Any Genre</option>
<option value="fiction">Fiction</option>
<option value="mystery">Mystery</option>
<option value="sci-fi">Science Fiction</option>
<option value="fantasy">Fantasy</option>
<option value="romance">Romance</option>
<option value="historical">Historical Fiction</option>
<option value="non-fiction">Non-Fiction</option>
<option value="biography">Biography</option>
<option value="self-help">Self-Help</option>
</select>
</div>
<div class="flex-1">
<label for="length" class="block text-sm font-medium text-gray-700 mb-2">Book Length</label>
<select id="length" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
<option value="">Any Length</option>
<option value="short">Short (under 200 pages)</option>
<option value="medium">Medium (200-400 pages)</option>
<option value="long">Long (400+ pages)</option>
</select>
</div>
</div>
<div class="mt-8">
<button id="recommendBtn" class="w-full sm:w-auto px-8 py-3 bg-indigo-600 text-white font-medium rounded-lg hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition flex items-center justify-center gap-2">
<i class="fas fa-book-open"></i>
Get Recommendations
</button>
</div>
</section>
<!-- Results Section -->
<section id="resultsSection" class="hidden">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-semibold text-gray-800">Recommended Books</h2>
<button id="newSearchBtn" class="text-indigo-600 hover:text-indigo-800 font-medium flex items-center gap-1">
<i class="fas fa-redo"></i>
New Search
</button>
</div>
<div id="loadingIndicator" class="hidden text-center py-12">
<div class="inline-block loading-spinner text-indigo-600 text-4xl mb-4">
<i class="fas fa-circle-notch"></i>
</div>
<p class="text-gray-600">Finding the perfect books for you...</p>
</div>
<div id="recommendationsContainer" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<!-- Book cards will be inserted here by JavaScript -->
</div>
</section>
<!-- Sample Book Card (hidden template) -->
<div id="bookCardTemplate" class="hidden">
<div class="book-card bg-white rounded-xl shadow-md overflow-hidden transition duration-300">
<div class="h-48 bg-gray-200 flex items-center justify-center">
<i class="fas fa-book text-5xl text-gray-400"></i>
</div>
<div class="p-5">
<h3 class="text-xl font-semibold text-gray-800 mb-1">Book Title</h3>
<p class="text-gray-600 text-sm mb-2">by <span class="author">Author Name</span></p>
<div class="flex flex-wrap gap-1 mb-3">
<span class="px-2 py-1 bg-indigo-100 text-indigo-800 text-xs rounded-full">Genre</span>
<span class="px-2 py-1 bg-indigo-100 text-indigo-800 text-xs rounded-full">Length</span>
</div>
<p class="text-gray-700 text-sm mb-4 line-clamp-3">Book description goes here with a brief summary of what the book is about...</p>
<div class="flex justify-between items-center">
<span class="text-sm text-gray-500">⭐ 4.5</span>
<a href="#" class="text-indigo-600 hover:text-indigo-800 text-sm font-medium">More details</a>
</div>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="mt-16 text-center text-gray-500 text-sm">
<p>© 2023 BookMatch. All rights reserved.</p>
</footer>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const recommendBtn = document.getElementById('recommendBtn');
const newSearchBtn = document.getElementById('newSearchBtn');
const resultsSection = document.getElementById('resultsSection');
const loadingIndicator = document.getElementById('loadingIndicator');
const recommendationsContainer = document.getElementById('recommendationsContainer');
const bookCardTemplate = document.getElementById('bookCardTemplate');
const userInput = document.getElementById('userInput');
// Sample book data (replace with your database query results)
const sampleBooks = [
{
title: "The Silent Patient",
author: "Alex Michaelides",
genre: "Psychological Thriller",
length: "Medium",
rating: 4.5,
description: "A woman shoots her husband and then never speaks another word. A criminal psychotherapist tries to unravel the mystery."
},
{
title: "Project Hail Mary",
author: "Andy Weir",
genre: "Science Fiction",
length: "Long",
rating: 4.8,
description: "An astronaut wakes up alone on a spaceship with no memory of who he is or how he got there. His mission is to save Earth from disaster."
},
{
title: "Where the Crawdads Sing",
author: "Delia Owens",
genre: "Literary Fiction",
length: "Medium",
rating: 4.7,
description: "A murder mystery and coming-of-age story set in the marshes of North Carolina, following a girl who raised herself in the wild."
},
{
title: "Atomic Habits",
author: "James Clear",
genre: "Self-Help",
length: "Medium",
rating: 4.6,
description: "A guide to building good habits and breaking bad ones, with practical strategies for making small changes that yield remarkable results."
},
{
title: "The Midnight Library",
author: "Matt Haig",
genre: "Fantasy Fiction",
length: "Medium",
rating: 4.2,
description: "Between life and death there is a library. Each book provides a chance to try another life you might have lived."
},
{
title: "Educated",
author: "Tara Westover",
genre: "Memoir",
length: "Medium",
rating: 4.7,
description: "A memoir about a woman who grew up in a survivalist family in Idaho and went on to earn a PhD from Cambridge University."
}
];
// Show recommendations
recommendBtn.addEventListener('click', function() {
const userText = userInput.value.trim();
if (!userText) {
alert("Please describe what kind of books you're looking for.");
return;
}
// Show loading indicator
resultsSection.classList.remove('hidden');
loadingIndicator.classList.remove('hidden');
recommendationsContainer.innerHTML = '';
// Simulate API/database call with timeout
setTimeout(() => {
loadingIndicator.classList.add('hidden');
// Filter books based on selected genre if any
const selectedGenre = document.getElementById('genre').value;
const selectedLength = document.getElementById('length').value;
let filteredBooks = sampleBooks;
if (selectedGenre) {
filteredBooks = filteredBooks.filter(book =>
book.genre.toLowerCase().includes(selectedGenre.toLowerCase()));
}
if (selectedLength) {
filteredBooks = filteredBooks.filter(book => {
if (selectedLength === 'short') return book.length === 'Short';
if (selectedLength === 'medium') return book.length === 'Medium';
if (selectedLength === 'long') return book.length === 'Long';
return true;
});
}
// Display recommendations
if (filteredBooks.length === 0) {
recommendationsContainer.innerHTML = `
<div class="col-span-full text-center py-8">
<i class="fas fa-book-open text-4xl text-gray-400 mb-4"></i>
<h3 class="text-xl font-medium text-gray-700 mb-2">No books found matching your criteria</h3>
<p class="text-gray-500">Try broadening your search or removing some filters.</p>
</div>
`;
} else {
filteredBooks.forEach(book => {
const card = bookCardTemplate.cloneNode(true);
card.classList.remove('hidden');
card.querySelector('h3').textContent = book.title;
card.querySelector('.author').textContent = book.author;
card.querySelector('.book-card .line-clamp-3').textContent = book.description;
// Update genre/length tags
const tagsContainer = card.querySelector('.flex-wrap');
tagsContainer.innerHTML = `
<span class="px-2 py-1 bg-indigo-100 text-indigo-800 text-xs rounded-full">${book.genre}</span>
<span class="px-2 py-1 bg-indigo-100 text-indigo-800 text-xs rounded-full">${book.length}</span>
`;
// Update rating
card.querySelector('span').textContent = `⭐ ${book.rating}`;
recommendationsContainer.appendChild(card);
});
}
}, 1500);
});
// New search button
newSearchBtn.addEventListener('click', function() {
resultsSection.classList.add('hidden');
userInput.value = '';
document.getElementById('genre').value = '';
document.getElementById('length').value = '';
userInput.focus();
});
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=apamplona2011/bookmatch" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |