-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpradeep.html
More file actions
712 lines (630 loc) · 24.4 KB
/
pradeep.html
File metadata and controls
712 lines (630 loc) · 24.4 KB
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vehicle Recommendation</title>
<link rel="stylesheet" href="styles2.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.9.4/lottie.min.js"></script>
<style>
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap");
/* Fullscreen Neuron Background */
#neuronCanvas {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: -1;
background: #050505;
}
body {
font-family: "Poppins", sans-serif;
background-color: #121212; /* Default dark theme */
animation: moveBackground 10s linear infinite; /* Apply animation */
color: white;
text-align: center;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
overflow-y: auto;
padding-top: 50px; /* Allow space for the fixed header */
transition: background 0.5s ease-in-out, color 0.5s ease-in-out;
}
@keyframes moveBackground {
0% {
background-position: 0% 0%;
}
100% {
background-position: 100% 100%;
}
}
.cover-page {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: white;
z-index: 100;
transition: opacity 0.5s ease, visibility 0.5s ease;
}
.hidden {
opacity: 0;
visibility: hidden;
}
.section {
padding: 20px;
margin-top: 20px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
width: 80%;
color: white;
transition: transform 0.3s ease-in-out;
}
.section:hover {
transform: scale(1.05);
}
h2 {
font-size: 2rem;
margin-bottom: 10px;
}
button {
padding: 10px;
margin: 5px;
background: #ff9800;
border: none;
border-radius: 5px;
cursor: pointer;
transition: 0.3s ease;
color: white;
font-size: 1rem;
}
button:hover {
background: #e68900;
transform: scale(1.1);
}
#result-box,
#compare-results,
#recommend-results {
margin-top: 20px;
padding: 15px;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 8px;
color: #fff;
font-size: 1rem;
display: flex;
align-items: flex-start;
}
#result-box img,
#compare-results img,
#recommend-results img {
width: 150px; /* Set a fixed width for images */
margin-right: 20px; /* Space between image and text */
transition: transform 0.3s ease;
}
#result-box img:hover,
#compare-results img:hover,
#recommend-results img:hover {
transform: scale(1.1); /* Scale image on hover */
}
#search {
padding: 8px;
font-size: 1rem;
border-radius: 5px;
margin-right: 10px;
}
.hidden-search {
display: none;
}
/* Share and Download Buttons */
.share-download {
margin-top: 20px;
}
.share-download button {
margin: 5px;
font-size: 1.5rem; /* Increase font size for symbols */
background: transparent; /* Make buttons transparent */
color: white; /* Keep text color white */
border: 1px solid white; /* Optional: Add border for visibility */
}
/* Loading GIF */
#loading {
display: none; /* Hidden by default */
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 200; /* Above other content */
width: 100px; /* Set the desired width */
height: 100px; /* Set the desired height */
}
/* New styles for hover effect */
.vehicle-image-container {
position: relative;
}
.vehicle-image-info {
position: absolute;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 10px;
display: none;
border-radius: 5px;
}
.vehicle-image-container:hover .vehicle-image-info {
display: block;
}
/* Table styles */
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
th,
td {
border: 1px solid #fff;
padding: 8px;
text-align: left;
}
th {
background-color: rgba(255, 255, 255, 0.2);
}
</style>
</head>
<body>
<canvas id="neuronCanvas"></canvas>
<div class="cover-page" id="cover">
<h1>Welcome to Vehicle Finder</h1>
<p>Your ultimate tool to find and compare vehicles</p>
<button onclick="startApp()">Continue</button>
</div>
<div style="display: flex; flex-direction: column; align-items: center">
<div class="theme-toggle hidden-search">
<button onclick="toggleTheme()">Toggle Dark/Light Theme</button>
</div>
<div id="user-profile" class="section hidden-search">
<h2>User Profile</h2>
<p id="profile-info">Not logged in</p>
<button onclick="showSearchHistory()">Search History</button>
<div id="search-history" class="hidden-search"></div>
</div>
<header class="section" id="search-section">
<h2>Search Vehicles</h2>
<input type="text" id="search" placeholder="Search for a vehicle..." />
<button onclick="searchVehicle()">Search</button>
<div id="result-box" class="result-container"></div>
<div class="share-download hidden" id="search-share-download">
<button onclick="shareInfo('search')">🔗</button>
<!-- Share symbol -->
<button onclick="downloadInfo('search')">⬇️</button>
<!-- Download symbol -->
</div>
</header>
<section id="comparison" class="section">
<h2>Compare Vehicles</h2>
<input type="text" id="vehicle1" placeholder="Enter first vehicle" />
<input type="text" id="vehicle2" placeholder="Enter second vehicle" />
<button onclick="compareVehicles()">Compare</button>
<div id="compare-results" class="result-container"></div>
<div class="share-download hidden" id="compare-share-download">
<button onclick="shareInfo('compare')">🔗</button>
<!-- Share symbol -->
<button onclick="downloadInfo('compare')">⬇️</button>
<!-- Download symbol -->
</div>
</section>
<section id="recommendation" class="section hidden-search">
<h2>Vehicle Recommendations</h2>
<input
type="text"
id="preferences"
placeholder="Enter your vehicle preferences..."
/>
<button onclick="getRecommendations()">Get Recommendations</button>
<div id="recommend-results" class="result-container"></div>
<div class="share-download hidden" id="recommend-share-download">
<button onclick="shareInfo('recommend')">🔗</button>
<!-- Share symbol -->
<button onclick="downloadInfo('recommend')">⬇️</button>
<!-- Download symbol -->
</div>
</section>
<div class="share-download">
<h2>Share or Download</h2>
<button onclick="shareInfo()">🔗</button>
<!-- Share symbol -->
<button onclick="downloadInfo()">⬇️</button>
<!-- Download symbol -->
</div>
</div>
<!-- Loading GIF -->
<img id="loading" src="loading.gif" alt="Loading..." />
<script>
const API_KEY = "AIzaSyDI7DWsDkSH57Bk7JcSAJjd2B895WrT0yM"; // Replace with your Gemini API Key
const CSE_ID = " AIzaSyDIm2lUqx7h5vYrC7kE8W787_qi9rO1VBY"; // Replace with your Google Custom Search Engine ID
const GOOGLE_API_KEY = "AIzaSyBV8VKuDN9gwEwmgTJXXYVK4mKqcIJoYCg"; // Replace with your Google API Key
const UNSPLASH_ACCESS_KEY = "jmRC7OJyJm0fOdMJxbd5kYwl2HQamnZBEH3nAXuAJ3w";
let isDarkTheme = true; // Default to dark theme
let searchHistory = []; // Array to store search history
function toggleTheme() {
isDarkTheme = !isDarkTheme;
document.body.style.backgroundColor = isDarkTheme
? "#121212"
: "#ffffff";
document.body.style.color = isDarkTheme ? "white" : "black";
document.body.style.opacity = isDarkTheme ? "1" : "0.4"; // Decrease opacity in light mode
document.querySelectorAll(".section").forEach((section) => {
section.style.background = isDarkTheme
? "rgba(255, 255, 255, 0.1)"
: "rgba(255, 255, 255, 0.8)";
});
}
function startApp() {
document.getElementById("cover").classList.add("hidden");
document
.getElementById("recommendation")
.classList.remove("hidden-search");
document
.getElementById("user-profile")
.classList.remove("hidden-search");
document
.querySelector(".theme-toggle")
.classList.remove("hidden-search"); // Show theme toggle
window.scrollTo(0, document.getElementById("recommendation").offsetTop); // Scroll to recommendations section
}
async function searchVehicle() {
const query = document.getElementById("search").value;
const resultsContainer = document.getElementById("result-box");
resultsContainer.innerHTML = "<p>Searching...</p>";
document.getElementById("loading").style.display = "block"; // Show loading GIF
if (!query) {
resultsContainer.innerHTML = "<p>Please enter a vehicle name.</p>";
document.getElementById("loading").style.display = "none"; // Hide loading GIF
return;
}
// Add the search query to the history
searchHistory.push(query);
updateSearchHistory();
try {
const response = await fetch(
`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${API_KEY}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
contents: [
{
parts: [
{
text: `Provide details of "${query}" including Overview, Performance, Interior, and Safety.`,
},
],
},
],
}),
}
);
if (!response.ok)
throw new Error(`API call failed with status ${response.status}`);
const data = await response.json();
if (!data?.candidates?.[0]?.content?.parts) {
resultsContainer.innerHTML = "<p>No vehicle details found.</p>";
document.getElementById("loading").style.display = "none"; // Hide loading GIF
return;
}
let formattedText = data.candidates[0].content.parts[0].text
.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>")
.replace(/\n/g, "<br>");
const imageUrl = await fetchUnsplashImage(query);
resultsContainer.innerHTML = `
<div class="vehicle-image-container">
<img src="${imageUrl}" alt="${query}" class="vehicle-image">
<div class="vehicle-image-info">
<strong>${query}</strong><br>
<span>Main Feature 1</span><br>
<span>Main Feature 2</span>
</div>
</div>
<div>
<h3 style="font-weight: bold;">Vehicle Details:</h3>
<div class="result-box">${formattedText}</div>
</div>
`;
// Show share and download buttons for search
document
.getElementById("search-share-download")
.classList.remove("hidden");
resultsContainer.classList.add("slide-in");
window.scrollTo(0, resultsContainer.offsetTop); // Scroll to result section after search
} catch (error) {
console.error("Error fetching data:", error);
resultsContainer.innerHTML = `<p>Error fetching vehicle details. Please check API setup.</p>`;
} finally {
document.getElementById("loading").style.display = "none"; // Hide loading GIF
}
}
async function fetchUnsplashImage(query) {
try {
const response = await fetch(
`https://api.unsplash.com/search/photos?query=${query}&client_id=${UNSPLASH_ACCESS_KEY}&per_page=1`
);
const data = await response.json();
return data.results && data.results.length > 0
? data.results[0].urls.small
: "https://via.placeholder.com/300"; // Default image if no results
} catch (error) {
console.error("Error fetching image:", error);
return "https://via.placeholder.com/300"; // Default fallback image
}
}
async function compareVehicles() {
const vehicle1 = document.getElementById("vehicle1").value;
const vehicle2 = document.getElementById("vehicle2").value;
const resultsContainer = document.getElementById("compare-results");
if (!vehicle1 || !vehicle2) {
resultsContainer.innerHTML =
"<p>Please enter both vehicle names.</p>";
return;
}
resultsContainer.innerHTML = "<p>Comparing...</p>";
document.getElementById("loading").style.display = "block"; // Show loading GIF
try {
const response = await fetch(
`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${API_KEY}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
contents: [
{
parts: [
{
text: `Compare ${vehicle1} with ${vehicle2}. Provide a detailed and structured comparison including performance, safety, fuel efficiency, and technology.`,
},
],
},
],
}),
}
);
const data = await response.json();
let formattedComparison = data.candidates[0].content.parts[0].text
.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>")
.replace(/\n/g, "<br>");
resultsContainer.innerHTML = `
<div class="vehicle-image-container">
<img src="https://via.placeholder.com/150" alt="${vehicle1}" class="vehicle-image">
<div class="vehicle-image-info">
<strong>${vehicle1}</strong><br>
<span>Main Feature 1</span><br>
<span>Main Feature 2</span>
</div>
</div>
<div class="vehicle-image-container">
<img src="https://via.placeholder.com/150" alt="${vehicle2}" class="vehicle-image">
<div class="vehicle-image-info">
<strong>${vehicle2}</strong><br>
<span>Main Feature 1</span><br>
<span>Main Feature 2</span>
</div>
</div>
<div class="result-box">
<h3 style="font-weight: bold;">Comparison: ${vehicle1} vs ${vehicle2}</h3>
<div>${formattedComparison}</div>
</div>
`;
// Show share and download buttons for comparison
document
.getElementById("compare-share-download")
.classList.remove("hidden");
} catch (error) {
console.error("Error fetching data:", error);
resultsContainer.innerHTML = `<p>Error comparing vehicles. Please check API setup.</p>`;
} finally {
document.getElementById("loading").style.display = "none"; // Hide loading GIF
}
}
async function getRecommendations() {
const preferences = document.getElementById("preferences").value;
const resultsContainer = document.getElementById("recommend-results");
if (!preferences) {
resultsContainer.innerHTML = "<p>Please enter your preferences.</p>";
return;
}
resultsContainer.innerHTML = "<p>Loading recommendations...</p>";
document.getElementById("loading").style.display = "block"; // Show loading GIF
try {
const response = await fetch(
`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${API_KEY}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
contents: [
{
parts: [
{
text: `Recommend vehicles based on these preferences: ${preferences}. Provide a variety of options for different categories.`,
},
],
},
],
}),
}
);
const data = await response.json();
let formattedRecommendations =
data.candidates[0].content.parts[0].text
.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>")
.replace(/\n/g, "<br>");
resultsContainer.innerHTML = `
<h3 style="font-weight: bold;">Recommended Vehicles:</h3>
<div class="result-box">${formattedRecommendations}</div>
`;
// Show share and download buttons for recommendations
document
.getElementById("recommend-share-download")
.classList.remove("hidden");
} catch (error) {
console.error("Error fetching recommendations:", error);
resultsContainer.innerHTML = `<p>Error fetching recommendations. Please check API setup.</p>`;
} finally {
document.getElementById("loading").style.display = "none"; // Hide loading GIF
}
}
function showSearchHistory() {
const historyContainer = document.getElementById("search-history");
if (searchHistory.length === 0) {
historyContainer.innerHTML = "<p>No search history available.</p>";
} else {
historyContainer.innerHTML =
"<h3>Search History:</h3><ul>" +
searchHistory.map((item) => `<li>${item}</li>`).join("") +
"</ul>";
}
historyContainer.classList.toggle("hidden-search");
}
function updateSearchHistory() {
const historyContainer = document.getElementById("search-history");
historyContainer.innerHTML =
"<h3>Search History:</h3><ul>" +
searchHistory.map((item) => `<li>${item}</li>`).join("") +
"</ul>";
}
function shareInfo(type) {
let data;
if (type === "search") {
data = document.getElementById("result-box").innerHTML;
} else if (type === "compare") {
data = document.getElementById("compare-results").innerHTML;
} else if (type === "recommend") {
data = document.getElementById("recommend-results").innerHTML;
}
const shareData = {
title: "Vehicle Finder",
text: data,
url: window.location.href,
};
navigator
.share(shareData)
.then(() => console.log("Share successful"))
.catch((error) => console.error("Error sharing:", error));
}
function downloadInfo(type) {
let data;
if (type === "search") {
data = document.getElementById("result-box").innerHTML;
} else if (type === "compare") {
data = document.getElementById("compare-results").innerHTML;
} else if (type === "recommend") {
data = document.getElementById("recommend-results").innerHTML;
}
const blob = new Blob([data], { type: "text/html" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "vehicle_info.html";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
const canvas = document.getElementById("neuronCanvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let neurons = [];
const neuronCount = 50;
const maxDistance = 120;
const mouseRepelRadius = 100;
// Generate Random Neurons
function createNeurons() {
for (let i = 0; i < neuronCount; i++) {
neurons.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 1.2,
vy: (Math.random() - 0.5) * 1.2,
});
}
}
createNeurons();
// Mouse Position
let mouse = { x: null, y: null };
canvas.addEventListener("mousemove", (event) => {
mouse.x = event.clientX;
mouse.y = event.clientY;
});
canvas.addEventListener("mouseleave", () => {
mouse.x = null;
mouse.y = null;
});
// Neuron Animation
function animateNeurons() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw and Move Neurons
for (let i = 0; i < neurons.length; i++) {
let neuron = neurons[i];
// Move neurons
neuron.x += neuron.vx;
neuron.y += neuron.vy;
// Bounce off walls
if (neuron.x <= 0 || neuron.x >= canvas.width) neuron.vx *= -1;
if (neuron.y <= 0 || neuron.y >= canvas.height) neuron.vy *= -1;
// Repel from Mouse
if (mouse.x && mouse.y) {
let dx = neuron.x - mouse.x;
let dy = neuron.y - mouse.y;
let distance = Math.sqrt(dx * dx + dy * dy);
if (distance < mouseRepelRadius) {
neuron.x += dx * 0.05;
neuron.y += dy * 0.05;
}
}
// Draw neuron
ctx.beginPath();
ctx.arc(neuron.x, neuron.y, 3, 0, Math.PI * 2);
ctx.fillStyle = "#ff9100";
ctx.shadowBlur = 8;
ctx.shadowColor = "#ff9100";
ctx.fill();
ctx.closePath();
// Connect Neurons
for (let j = i + 1; j < neurons.length; j++) {
let other = neurons[j];
let dx = neuron.x - other.x;
let dy = neuron.y - other.y;
let distance = Math.sqrt(dx * dx + dy * dy);
if (distance < maxDistance) {
ctx.beginPath();
ctx.moveTo(neuron.x, neuron.y);
ctx.lineTo(other.x, other.y);
ctx.strokeStyle = `rgba(255, 145, 0, ${
1 - distance / maxDistance
})`;
ctx.lineWidth = 1;
ctx.stroke();
}
}
}
requestAnimationFrame(animateNeurons);
}
animateNeurons();
// Resize Handling
window.addEventListener("resize", () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
</script>
</body>
</html>