Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import { useRef } from "react"; | |
const SIMULATED_LOGS = [ | |
"[INFO] Initializing benchmark generation...", | |
"[INFO] Generating base configuration file...", | |
"[SUCCESS] Stage completed: configuration", | |
"[INFO] Finding available providers for models...", | |
"[SUCCESS] Stage completed: provider_check", | |
"[INFO] Starting ingestion process...", | |
"[SUCCESS] Stage completed: ingestion", | |
"[INFO] Processing document content for upload...", | |
"[SUCCESS] Stage completed: upload_ingest_to_hub", | |
"[INFO] Generating document summary...", | |
"[SUCCESS] Stage completed: summarization", | |
"[INFO] Chunking content for better analysis...", | |
"[SUCCESS] Stage completed: chunking", | |
"[INFO] Generating single-shot questions...", | |
"[SUCCESS] Stage completed: single_shot_question_generation", | |
"[SUCCESS] Benchmark process completed successfully", | |
]; | |
export const useBenchmarkSimulation = ( | |
setGenerationLogs, | |
setGenerationComplete, | |
onComplete, | |
sessionId | |
) => { | |
const simulationIntervalRef = useRef(null); | |
const SIMULATION_DURATION = 80000; // 20 seconds | |
const startSimulation = () => { | |
setGenerationLogs([]); | |
let currentStep = 0; | |
const addNextLog = () => { | |
if (currentStep < SIMULATED_LOGS.length) { | |
setGenerationLogs((prevLogs) => [ | |
...prevLogs, | |
SIMULATED_LOGS[currentStep], | |
]); | |
currentStep++; | |
if (currentStep >= SIMULATED_LOGS.length) { | |
setTimeout(() => { | |
setGenerationComplete(true); | |
clearInterval(simulationIntervalRef.current); | |
if (onComplete) { | |
onComplete({ | |
success: true, | |
sessionId, | |
logs: SIMULATED_LOGS, | |
}); | |
} | |
}, 1000); | |
} | |
} | |
}; | |
const totalSteps = SIMULATED_LOGS.length; | |
const intervalPerStep = SIMULATION_DURATION / totalSteps; | |
simulationIntervalRef.current = setInterval(addNextLog, intervalPerStep); | |
}; | |
return { startSimulation }; | |
}; | |