Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 4,162 Bytes
81e0b0c |
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 |
import React from "react";
import { Box, Typography, CircularProgress, Alert, Paper } from "@mui/material";
import { useNavigate, useSearchParams } from "react-router-dom";
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
import { useSimulation } from "./hooks/useSimulation";
import { useTimer } from "./hooks/useTimer";
import { useEvaluation } from "./hooks/useEvaluation";
import ErrorDisplay from "../common/ErrorDisplay";
const BenchmarkEvaluation = ({ sessionId, isDefaultDocument, onComplete }) => {
const [searchParams] = useSearchParams();
const isDefault =
isDefaultDocument ||
["the-bitter-lesson", "hurricane-faq", "pokemon-guide"].includes(sessionId);
const navigate = useNavigate();
// Use our custom hooks
const { formatElapsedTime, stopTimer } = useTimer();
const {
startingMessageIndex,
evaluationComplete: simulationComplete,
currentMessage,
} = useSimulation(() => {
if (onComplete) {
onComplete();
}
});
const {
error,
evaluationComplete: realComplete,
currentStep,
evaluationStarted,
startEvaluation,
currentStepLabel,
totalSteps,
} = useEvaluation(sessionId, () => {
if (onComplete) {
onComplete();
}
});
// Handle automatic redirection when evaluation is complete
React.useEffect(() => {
if (realComplete || simulationComplete) {
navigate(`/evaluation-display?session=${sessionId}`);
}
}, [realComplete, simulationComplete, sessionId, navigate]);
// Start evaluation if not default and not started
React.useEffect(() => {
if (!isDefault && !evaluationStarted) {
startEvaluation();
}
}, [isDefault, evaluationStarted, startEvaluation]);
// Stop timer when complete
React.useEffect(() => {
if (realComplete || simulationComplete) {
stopTimer();
}
}, [realComplete, simulationComplete, stopTimer]);
const isComplete = realComplete || simulationComplete;
const currentStepInfo = isDefault
? `${currentMessage.message} (${currentMessage.step}/${currentMessage.totalSteps})`
: `${currentStepLabel} (${currentStep + 1}/${totalSteps})`;
return (
<Paper
elevation={3}
sx={{
p: 4,
mt: 3,
mb: 3,
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
minHeight: 200,
position: "relative",
}}
>
{/* Temps estimé */}
<Box
sx={{
position: "absolute",
top: 12,
right: 12,
backgroundColor: "rgba(0, 0, 0, 0.04)",
borderRadius: "4px",
px: 1,
py: 0.5,
display: "inline-flex",
alignItems: "center",
}}
>
<Typography
variant="caption"
sx={{
fontSize: "0.675rem",
color: "text.secondary",
fontWeight: 500,
}}
>
Estimated time ~ 1m30s
</Typography>
</Box>
{error ? (
<ErrorDisplay error={error} />
) : (
<>
{isComplete ? (
<Alert severity="success" sx={{ width: "100%", mb: 3 }}>
Evaluation completed successfully!
</Alert>
) : (
<>
<CircularProgress size={60} sx={{ mb: 2 }} />
<Typography variant="h6" component="div" gutterBottom>
Benchmark evaluation...
</Typography>
{/* Step progress indicator */}
<Typography variant="body1" color="text.secondary">
{currentStepInfo}
</Typography>
{/* Timer display */}
<Box
sx={{
display: "flex",
alignItems: "center",
mt: 1,
color: "text.secondary",
opacity: 0.5,
}}
>
<Typography variant="body2">{formatElapsedTime()}</Typography>
</Box>
</>
)}
</>
)}
</Paper>
);
};
export default BenchmarkEvaluation;
|