Spaces:
Running
Running
Download src/components/certification-flow/GenerationLoader.tsx from Sarvesh213/getcert-backend: direct link, hf CLI and curl.
- Browser
- Download file 5.67 kB
-
https://huggingface.co/spaces/Sarvesh213/getcert-backend/resolve/main/src/components/certification-flow/GenerationLoader.tsx
- Command line
-
hf download hf://spaces/Sarvesh213/getcert-backend/src/components/certification-flow/GenerationLoader.tsx
-
curl -L -o GenerationLoader.tsx https://huggingface.co/spaces/Sarvesh213/getcert-backend/resolve/main/src/components/certification-flow/GenerationLoader.tsx
5.67 kB
| import { useEffect, useRef, useState } from 'react'; | |
| import { CheckCircle2 } from 'lucide-react'; | |
| import { Component as PencilLoader } from '@/components/ui/loader-1'; | |
| import { resolveCanonicalCourseTitle } from '../../utils/courseTitleResolver'; | |
| interface GenerationLoaderProps { | |
| courseName: string; | |
| /** 'course' = building the learning path, 'assessment' = building exam questions */ | |
| mode?: 'course' | 'assessment'; | |
| } | |
| type Stage = { label: string; atSeconds: number }; | |
| const COURSE_STAGES: Omit<Stage, 'atSeconds'>[] = [ | |
| { label: 'Analyzing curriculum structure' }, | |
| { label: 'Curating verified learning resources' }, | |
| { label: 'Matching video content to topics' }, | |
| { label: 'Assembling your learning path' }, | |
| ]; | |
| const ASSESSMENT_STAGES: Omit<Stage, 'atSeconds'>[] = [ | |
| { label: 'Loading course context and video transcript signals' }, | |
| { label: 'Drafting question set across difficulty tiers' }, | |
| { label: 'Calibrating answer keys and grading rubrics' }, | |
| { label: 'Running final quality validation' }, | |
| ]; | |
| /** | |
| * Asymptotic progress: moves fast early, creeps toward ~92% but never | |
| * completes on its own β completion is only ever shown by the real result | |
| * replacing this screen. | |
| */ | |
| function progressPercent(elapsedMs: number): number { | |
| const t = elapsedMs / 1000; | |
| const pct = 92 * (1 - Math.exp(-t / 12)); | |
| return Math.min(92, Math.max(2, Math.round(pct))); | |
| } | |
| export function GenerationLoader({ courseName, mode = 'course' }: GenerationLoaderProps) { | |
| const baseStages = mode === 'assessment' ? ASSESSMENT_STAGES : COURSE_STAGES; | |
| // Spread stage handoffs across a realistic window (~8s apart) regardless of | |
| // actual model latency β stages reflect real pipeline phases, timed evenly. | |
| const stages: Stage[] = baseStages.map((stage, index) => ({ | |
| ...stage, | |
| atSeconds: 1 + index * 7, | |
| })); | |
| const [elapsedMs, setElapsedMs] = useState(0); | |
| const startRef = useRef<number>(Date.now()); | |
| useEffect(() => { | |
| startRef.current = Date.now(); | |
| const interval = setInterval(() => { | |
| setElapsedMs(Date.now() - startRef.current); | |
| }, 200); | |
| return () => clearInterval(interval); | |
| }, []); | |
| const elapsedSeconds = Math.floor(elapsedMs / 1000); | |
| const activeStageIndex = stages.reduce( | |
| (acc, stage, index) => (elapsedSeconds >= stage.atSeconds ? index : acc), | |
| 0, | |
| ); | |
| const percent = progressPercent(elapsedMs); | |
| const title = | |
| mode === 'assessment' ? 'Preparing your assessment' : 'Creating your learning path'; | |
| const etaLabel = | |
| mode === 'assessment' | |
| ? 'Questions are generated fresh for this course β usually 15β30 seconds' | |
| : 'Your learning path is created fresh β usually 15β30 seconds'; | |
| return ( | |
| <div className="bg-slate-50 min-h-[60vh] flex items-center justify-center py-16 px-4 font-sans transition-colors duration-200"> | |
| <div className="relative max-w-md w-full mx-auto bg-white rounded-2xl border border-slate-200/90 p-8 shadow-sm"> | |
| <div className="text-center"> | |
| {/* Animated Pencil Loader */} | |
| <div className="relative mx-auto mb-4 flex items-center justify-center"> | |
| <PencilLoader size={120} /> | |
| </div> | |
| <h1 className="text-xl sm:text-2xl font-extrabold tracking-tight text-slate-900 mb-1"> | |
| {title} | |
| </h1> | |
| <p className="text-xs font-semibold text-blue-700 mb-6 tracking-wide"> | |
| {resolveCanonicalCourseTitle(courseName)} | |
| </p> | |
| {/* Real progress bar β asymptotic toward 92% */} | |
| <div className="w-full bg-slate-100 rounded-full h-2 mb-2 overflow-hidden"> | |
| <div | |
| className="bg-[#132F50] h-full rounded-full transition-all duration-500 ease-out" | |
| style={{ width: `${percent}%` }} | |
| /> | |
| </div> | |
| <div className="flex justify-between text-xs text-slate-500 mb-6 font-medium"> | |
| <span className="font-semibold text-slate-700">{percent}% processed</span> | |
| <span className="tabular-nums">Elapsed: {elapsedSeconds}s</span> | |
| </div> | |
| {/* Live pipeline checklist */} | |
| <div className="text-left space-y-2.5 mb-6 bg-slate-50 rounded-xl p-4 border border-slate-200/80"> | |
| {stages.map((stage, index) => { | |
| const isDone = index < activeStageIndex; | |
| const isActive = index === activeStageIndex; | |
| return ( | |
| <div key={stage.label} className="flex items-center gap-2.5 text-xs"> | |
| <span className="w-5 text-center shrink-0 flex items-center justify-center"> | |
| {isDone ? ( | |
| <CheckCircle2 className="w-4 h-4 text-emerald-600" /> | |
| ) : isActive ? ( | |
| <span className="w-2.5 h-2.5 rounded-full bg-blue-600 animate-ping" /> | |
| ) : ( | |
| <span className="w-2 h-2 rounded-full bg-slate-300 inline-block" /> | |
| )} | |
| </span> | |
| <span | |
| className={`${ | |
| isDone | |
| ? 'text-slate-400 font-normal line-through' | |
| : isActive | |
| ? 'font-semibold text-slate-900' | |
| : 'text-slate-500 font-normal' | |
| }`} | |
| > | |
| {stage.label} | |
| </span> | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| <p className="text-xs text-slate-500 flex items-center justify-center font-medium"> | |
| <span>{etaLabel}</span> | |
| </p> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |