File size: 25,784 Bytes
a566fb0 |
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 |
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { createPageUrl } from '@/utils';
import { motion, AnimatePresence } from 'framer-motion';
import { Brain, CheckCircle2, XCircle, ArrowLeft, Trophy, RotateCcw, Sparkles, Target } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Progress } from '@/components/ui/progress';
import confetti from 'canvas-confetti';
const questions = [
{
id: 1,
question: "In YOLO (You Only Look Once), what makes it faster than traditional object detection methods?",
options: [
"It uses smaller images",
"It processes the entire image in a single pass instead of multiple regions",
"It only detects one object at a time",
"It uses black and white images"
],
correct: 1,
topic: "Object Detection"
},
{
id: 2,
question: "What does a confidence score of 95% mean in object detection?",
options: [
"The object is 95% visible in the image",
"The AI is 95% certain about its prediction",
"95% of the object is inside the bounding box",
"The detection took 95% of the processing time"
],
correct: 1,
topic: "Object Detection"
},
{
id: 3,
question: "How many keypoints does a standard pose estimation model typically track on the human body?",
options: [
"7 keypoints",
"10 keypoints",
"17 keypoints",
"25 keypoints"
],
correct: 2,
topic: "Pose Estimation"
},
{
id: 4,
question: "What are 'skeleton lines' in pose estimation?",
options: [
"Lines that show bones in an X-ray",
"Connections between keypoints showing body structure",
"Errors in the detection algorithm",
"Grid lines dividing the image"
],
correct: 1,
topic: "Pose Estimation"
},
{
id: 5,
question: "Which of these is NOT one of the 7 basic emotions in FER (Facial Emotion Recognition)?",
options: [
"Fear",
"Disgust",
"Confused",
"Surprise"
],
correct: 2,
topic: "Emotion Recognition"
},
{
id: 6,
question: "Why do facial emotion recognition models use 48Γ48 pixel images?",
options: [
"Larger images don't work with AI",
"Smaller size allows faster processing while retaining key facial features",
"48Γ48 is the size of human faces",
"It's the only size cameras can capture"
],
correct: 1,
topic: "Emotion Recognition"
},
{
id: 7,
question: "Which technology would be BEST for analyzing a dancer's movements in real-time?",
options: [
"Object Detection",
"Emotion Recognition",
"Pose Estimation",
"Voice Recognition"
],
correct: 2,
topic: "Pose Estimation"
},
{
id: 8,
question: "In object detection, what happens during 'non-max suppression'?",
options: [
"The AI stops detecting objects",
"Duplicate or overlapping bounding boxes are removed",
"The confidence threshold is lowered",
"The image brightness is reduced"
],
correct: 1,
topic: "Object Detection"
},
{
id: 9,
question: "Why is consent important before using emotion recognition technology on someone?",
options: [
"It makes the AI more accurate",
"People have a right to privacy and to know when they're being analyzed",
"It's required by all cameras",
"Consent improves the lighting in photos"
],
correct: 1,
topic: "Emotion Recognition"
},
{
id: 10,
question: "What is the main advantage of using grayscale images in emotion recognition instead of color?",
options: [
"Grayscale images look more professional",
"Color doesn't exist in emotions",
"It reduces processing complexity and focuses on facial structure rather than skin tone",
"Grayscale cameras are cheaper"
],
correct: 2,
topic: "Emotion Recognition"
},
{
id: 11,
question: "If pose estimation detects 2 people in a video, how many total keypoints might it track?",
options: [
"17 keypoints total",
"34 keypoints (17 per person)",
"25 keypoints total",
"10 keypoints total"
],
correct: 1,
topic: "Pose Estimation"
},
{
id: 12,
question: "What is a potential bias concern with emotion recognition AI?",
options: [
"It works too slowly",
"It might perform differently across different cultures, ages, or demographics",
"It can only detect happy emotions",
"It requires too much computer power"
],
correct: 1,
topic: "Emotion Recognition"
}
];
// 60-minute TTL logic (same as Lessons.js)
const COMPLETED_KEY = 'completedChapters_v1';
const TTL_MS = 60 * 60 * 1000;
function checkLessonsCompleted() {
try {
const raw = localStorage.getItem(COMPLETED_KEY);
if (!raw) return false;
const parsed = JSON.parse(raw);
const savedAt = parsed?.savedAt;
const value = parsed?.value;
if (!Array.isArray(value) || typeof savedAt !== 'number') return false;
if (Date.now() - savedAt > TTL_MS) {
localStorage.removeItem(COMPLETED_KEY);
return false;
}
return value.length === 3;
} catch {
return false;
}
}
export default function Quiz() {
const [started, setStarted] = useState(false);
const [currentQuestion, setCurrentQuestion] = useState(0);
const [selectedAnswer, setSelectedAnswer] = useState(null);
const [showResult, setShowResult] = useState(false);
const [score, setScore] = useState(0);
const [answers, setAnswers] = useState([]);
const [finished, setFinished] = useState(false);
const [allLessonsCompleted, setAllLessonsCompleted] = useState(checkLessonsCompleted);
// Trigger confetti when finished with perfect score
useEffect(() => {
if (finished && score === questions.length) {
triggerConfetti();
}
}, [finished, score]);
const triggerConfetti = () => {
const duration = 5 * 1000;
const animationEnd = Date.now() + duration;
const defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 0 };
const random = (min, max) => Math.random() * (max - min) + min;
const interval = setInterval(function() {
const timeLeft = animationEnd - Date.now();
if (timeLeft <= 0) {
return clearInterval(interval);
}
const particleCount = 50 * (timeLeft / duration);
// Since particles fall down, start a bit higher than random
confetti({
...defaults,
particleCount,
origin: { x: random(0.1, 0.3), y: Math.random() - 0.2 }
});
confetti({
...defaults,
particleCount,
origin: { x: random(0.7, 0.9), y: Math.random() - 0.2 }
});
}, 250);
};
const handleStart = () => {
setStarted(true);
setCurrentQuestion(0);
setScore(0);
setAnswers([]);
setFinished(false);
};
const handleAnswer = (index) => {
if (showResult) return;
setSelectedAnswer(index);
setShowResult(true);
const isCorrect = index === questions[currentQuestion].correct;
if (isCorrect) {
setScore(score + 1);
}
setAnswers([...answers, { questionId: currentQuestion, selected: index, correct: isCorrect }]);
};
const handleNext = () => {
if (currentQuestion < questions.length - 1) {
setCurrentQuestion(currentQuestion + 1);
setSelectedAnswer(null);
setShowResult(false);
} else {
setFinished(true);
}
};
const getScoreMessage = () => {
const percentage = (score / questions.length) * 100;
if (percentage === 100) return { emoji: "π", message: "PERFECT SCORE! You're an AI Vision Master!" };
if (percentage >= 80) return { emoji: "π", message: "Amazing! You really know your AI stuff!" };
if (percentage >= 60) return { emoji: "π", message: "Good job! Keep learning and you'll be an expert!" };
if (percentage >= 40) return { emoji: "π", message: "Nice try! Review the lessons and try again!" };
return { emoji: "πͺ", message: "Don't give up! Go through the lessons and come back stronger!" };
};
// Start Screen
if (!started) {
return (
<div className="min-h-screen bg-gradient-to-br from-slate-900 via-purple-900 to-slate-900 pt-24 pb-12 px-6">
<div className="fixed inset-0 overflow-hidden pointer-events-none">
<div className="absolute top-20 left-10 w-72 h-72 bg-yellow-500/20 rounded-full blur-3xl animate-pulse" />
<div className="absolute bottom-20 right-10 w-96 h-96 bg-orange-500/20 rounded-full blur-3xl animate-pulse" />
</div>
<div className="max-w-2xl mx-auto relative text-center">
<Link to={createPageUrl('Home')}>
<Button className="text-white/70 hover:text-white mb-8 bg-transparent border-0 hover:bg-white/5">
<ArrowLeft className="w-4 h-4 mr-2" />
Back to Home
</Button>
</Link>
<motion.div
initial={{ scale: 0 }}
animate={{ scale: 1 }}
transition={{ type: "spring" }}
className="w-32 h-32 mx-auto rounded-3xl bg-gradient-to-br from-yellow-500 to-orange-500 flex items-center justify-center shadow-2xl shadow-yellow-500/30 mb-8"
>
<Target className="w-16 h-16 text-white" />
</motion.div>
<motion.h1
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
className="text-4xl md:text-5xl font-black text-white mb-4"
>
AI Vision Quiz
</motion.h1>
<motion.p
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.1 }}
className="text-xl text-white/70 mb-8"
>
Test your knowledge with {questions.length} questions about Object Detection, Pose Estimation, and Emotion Recognition!
</motion.p>
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.2 }}
className="bg-white/5 backdrop-blur-xl rounded-3xl p-8 border border-white/10 mb-8"
>
<div className="grid grid-cols-3 gap-4 text-center">
<div>
<div className="text-3xl font-bold text-cyan-400">{questions.length}</div>
<div className="text-white/60">Questions</div>
</div>
<div>
<div className="text-3xl font-bold text-purple-400">3</div>
<div className="text-white/60">Topics</div>
</div>
<div>
<div className="text-3xl font-bold text-emerald-400">β</div>
<div className="text-white/60">Retries</div>
</div>
</div>
</motion.div>
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.3 }}
>
{allLessonsCompleted ? (
<Button
onClick={handleStart}
size="lg"
className="text-xl px-12 py-8 bg-gradient-to-r from-yellow-500 to-orange-500 hover:from-yellow-600 hover:to-orange-600 rounded-2xl shadow-2xl shadow-orange-500/30 text-white font-bold border-0 transition-all hover:scale-105"
>
<Sparkles className="w-6 h-6 mr-2" />
Start Quiz
</Button>
) : (
<div>
<Button
disabled
size="lg"
className="text-xl px-12 py-8 bg-slate-700 text-slate-400 rounded-2xl font-bold border-0 cursor-not-allowed opacity-60 mb-4"
>
π Quiz Locked
</Button>
<p className="text-white/60">Complete all 3 lessons to unlock the quiz!</p>
<Link to={createPageUrl('Lessons')} className="inline-block mt-4">
<Button className="bg-blue-600 hover:bg-blue-700 text-white border-0 rounded-xl px-6 py-3">
Go to Lessons
</Button>
</Link>
</div>
)}
</motion.div>
</div>
</div>
);
}
// Results Screen
if (finished) {
const { emoji, message } = getScoreMessage();
const percentage = Math.round((score / questions.length) * 100);
return (
<div className="min-h-screen bg-gradient-to-br from-slate-900 via-purple-900 to-slate-900 pt-24 pb-12 px-6">
<div className="fixed inset-0 overflow-hidden pointer-events-none">
<div className="absolute top-20 left-10 w-72 h-72 bg-yellow-500/20 rounded-full blur-3xl animate-pulse" />
<div className="absolute bottom-20 right-10 w-96 h-96 bg-orange-500/20 rounded-full blur-3xl animate-pulse" />
</div>
<div className="max-w-2xl mx-auto relative">
<motion.div
initial={{ scale: 0 }}
animate={{ scale: 1 }}
transition={{ type: "spring" }}
className="text-center"
>
<div className="text-8xl mb-6">{emoji}</div>
<h1 className="text-4xl md:text-5xl font-black text-white mb-4">
Quiz Complete!
</h1>
<div className="bg-white/5 backdrop-blur-xl rounded-3xl p-8 border border-white/10 mb-8">
<div className="text-6xl font-black text-transparent bg-clip-text bg-gradient-to-r from-yellow-400 to-orange-400 mb-2">
{score}/{questions.length}
</div>
<div className="text-xl text-white/70 mb-6">
{percentage}% Correct
</div>
<Progress value={percentage} className="h-4 bg-white/10" />
<p className="text-white/80 mt-6 text-lg">{message}</p>
</div>
{/* Answer Summary */}
<div className="bg-white/5 backdrop-blur-xl rounded-3xl p-6 border border-white/10 mb-8">
<h3 className="text-lg font-bold text-white mb-4">Your Answers</h3>
<div className="grid grid-cols-5 gap-2">
{answers.map((answer, i) => (
<motion.div
key={i}
initial={{ scale: 0 }}
animate={{ scale: 1 }}
transition={{ delay: i * 0.05 }}
className={`w-12 h-12 rounded-xl flex items-center justify-center font-bold text-white ${
answer.correct
? 'bg-gradient-to-br from-emerald-500 to-teal-500'
: 'bg-gradient-to-br from-red-500 to-rose-500'
}`}
>
{i + 1}
</motion.div>
))}
</div>
</div>
<div className="flex flex-col sm:flex-row gap-4 justify-center mb-12">
<Button
onClick={handleStart}
size="lg"
className="bg-gradient-to-r from-yellow-500 to-orange-500 hover:from-yellow-600 hover:to-orange-600 rounded-xl text-white font-bold border-0 px-8 py-6 text-lg shadow-xl shadow-orange-500/25 transition-all hover:scale-105"
>
<RotateCcw className="w-5 h-5 mr-2" />
Try Again
</Button>
<Link to={createPageUrl('Lessons')}>
<Button
size="lg"
className="border-2 border-white/30 text-white bg-white/5 hover:bg-white/10 rounded-xl w-full px-8 py-6 text-lg font-bold transition-all"
>
Review Lessons
</Button>
</Link>
</div>
{/* Test It Yourself Section */}
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.3 }}
className="bg-gradient-to-br from-blue-500/10 to-purple-500/10 rounded-3xl p-10 border border-blue-500/20"
>
<div className="text-center mb-6">
<div className="text-5xl mb-4">π</div>
<h2 className="text-3xl font-black text-white mb-3">Ready to Test It Yourself?</h2>
<p className="text-white/70 text-lg mb-8">
Now that you've mastered the concepts, try building your own AI vision projects!
</p>
</div>
<div className="grid md:grid-cols-3 gap-4 mb-8">
<div className="bg-white/5 rounded-2xl p-6 border border-white/10">
<div className="text-3xl mb-3">ποΈ</div>
<h3 className="text-white font-bold mb-2">Object Detection</h3>
<p className="text-white/60 text-sm">Build your own detector</p>
</div>
<div className="bg-white/5 rounded-2xl p-6 border border-white/10">
<div className="text-3xl mb-3">π</div>
<h3 className="text-white font-bold mb-2">Pose Tracking</h3>
<p className="text-white/60 text-sm">Create motion games</p>
</div>
<div className="bg-white/5 rounded-2xl p-6 border border-white/10">
<div className="text-3xl mb-3">π</div>
<h3 className="text-white font-bold mb-2">Emotion AI</h3>
<p className="text-white/60 text-sm">Analyze expressions</p>
</div>
</div>
<Button
size="lg"
onClick={() => {
window.location.href = "/Lab-Selection.html";
}}
className="w-full bg-gradient-to-r from-blue-500 via-purple-500 to-pink-500 hover:from-blue-600 hover:via-purple-600 hover:to-pink-600 text-white font-bold text-xl py-8 rounded-2xl border-0 shadow-2xl transition-all hover:scale-105"
>
<Sparkles className="w-6 h-6 mr-3" />
Launch AI Playground
</Button>
</motion.div>
</motion.div>
</div>
</div>
);
}
// Quiz Question Screen
const question = questions[currentQuestion];
return (
<div className="min-h-screen bg-gradient-to-br from-slate-900 via-purple-900 to-slate-900 pt-24 pb-12 px-6">
<div className="fixed inset-0 overflow-hidden pointer-events-none">
<div className="absolute top-20 left-10 w-72 h-72 bg-yellow-500/20 rounded-full blur-3xl animate-pulse" />
<div className="absolute bottom-20 right-10 w-96 h-96 bg-orange-500/20 rounded-full blur-3xl animate-pulse" />
</div>
<div className="max-w-2xl mx-auto relative">
{/* Progress */}
<div className="mb-8">
<div className="flex items-center justify-between text-white/60 mb-2">
<span>Question {currentQuestion + 1} of {questions.length}</span>
<span className="px-3 py-1 rounded-full bg-white/10 text-sm">{question.topic}</span>
</div>
<Progress
value={((currentQuestion + 1) / questions.length) * 100}
className="h-2 bg-white/10"
/>
</div>
{/* Question */}
<AnimatePresence mode="wait">
<motion.div
key={currentQuestion}
initial={{ opacity: 0, x: 50 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -50 }}
>
<div className="bg-white/5 backdrop-blur-xl rounded-3xl p-8 border border-white/10 mb-6">
<div className="flex items-start gap-4 mb-6">
<div className="w-12 h-12 rounded-xl bg-gradient-to-br from-yellow-500 to-orange-500 flex items-center justify-center flex-shrink-0">
<Brain className="w-6 h-6 text-white" />
</div>
<h2 className="text-2xl font-bold text-white leading-relaxed">
{question.question}
</h2>
</div>
{/* Options */}
<div className="space-y-3">
{question.options.map((option, index) => {
const isSelected = selectedAnswer === index;
const isCorrect = index === question.correct;
const showCorrect = showResult && isCorrect;
const showWrong = showResult && isSelected && !isCorrect;
return (
<motion.button
key={index}
onClick={() => handleAnswer(index)}
disabled={showResult}
className={`w-full p-4 rounded-2xl text-left transition-all border-2 ${
showCorrect
? 'bg-emerald-500/20 border-emerald-500 text-white'
: showWrong
? 'bg-red-500/20 border-red-500 text-white'
: isSelected
? 'bg-white/20 border-white/40 text-white'
: 'bg-white/5 border-white/10 text-white/80 hover:bg-white/10 hover:border-white/20'
}`}
whileHover={!showResult ? { scale: 1.02 } : {}}
whileTap={!showResult ? { scale: 0.98 } : {}}
>
<div className="flex items-center gap-4">
<div className={`w-10 h-10 rounded-xl flex items-center justify-center font-bold ${
showCorrect
? 'bg-emerald-500 text-white'
: showWrong
? 'bg-red-500 text-white'
: 'bg-white/10 text-white/60'
}`}>
{showCorrect ? (
<CheckCircle2 className="w-5 h-5" />
) : showWrong ? (
<XCircle className="w-5 h-5" />
) : (
String.fromCharCode(65 + index)
)}
</div>
<span className="text-lg">{option}</span>
</div>
</motion.button>
);
})}
</div>
</div>
{/* Feedback */}
<AnimatePresence>
{showResult && (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
className={`rounded-2xl p-6 mb-6 ${
selectedAnswer === question.correct
? 'bg-gradient-to-br from-emerald-500/20 to-teal-500/20 border border-emerald-500/30'
: 'bg-gradient-to-br from-red-500/20 to-rose-500/20 border border-red-500/30'
}`}
>
<div className="flex items-center gap-3">
{selectedAnswer === question.correct ? (
<>
<CheckCircle2 className="w-8 h-8 text-emerald-400" />
<div>
<h3 className="text-xl font-bold text-white">Correct! π</h3>
<p className="text-white/70">Great job! You got this one right.</p>
</div>
</>
) : (
<>
<XCircle className="w-8 h-8 text-red-400" />
<div>
<h3 className="text-xl font-bold text-white">Not quite! π€</h3>
<p className="text-white/70">
The correct answer was: {question.options[question.correct]}
</p>
</div>
</>
)}
</div>
</motion.div>
)}
</AnimatePresence>
{/* Next Button */}
{showResult && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
className="text-center"
>
<Button
onClick={handleNext}
size="lg"
className="bg-gradient-to-r from-blue-500 to-purple-600 hover:from-blue-600 hover:to-purple-700 rounded-2xl px-12 py-6 text-lg font-bold text-white border-0 shadow-xl shadow-purple-500/30 transition-all hover:scale-105"
>
{currentQuestion < questions.length - 1 ? 'Next Question β' : 'β¨ See Results'}
</Button>
</motion.div>
)}
</motion.div>
</AnimatePresence>
</div>
</div>
);
}
|