import React, { useState } from "react";
import {
Box,
Typography,
Paper,
Button,
Divider,
Card,
CardContent,
Link,
CircularProgress,
Tooltip,
} from "@mui/material";
import PlayArrowIcon from "@mui/icons-material/PlayArrow";
import AssessmentIcon from "@mui/icons-material/Assessment";
import LinkIcon from "@mui/icons-material/Link";
import DownloadIcon from "@mui/icons-material/Download";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
/**
* Component to display benchmark information and evaluation button
*
* @param {Object} props - Component props
* @param {Array} props.sampleQuestions - Array of sample questions to display
* @param {Function} props.onStartEvaluation - Function to call when evaluation button is clicked
* @param {string} props.sessionId - Session ID used for the benchmark generation
* @param {string} props.datasetUrl - URL to the Hugging Face dataset
* @returns {JSX.Element} Benchmark display component
*/
const BenchmarkDisplay = ({
sampleQuestions = [],
onStartEvaluation,
sessionId,
datasetUrl,
}) => {
const [isDownloading, setIsDownloading] = useState(false);
// Default questions if none provided
const questions =
sampleQuestions.length > 0
? sampleQuestions
: [
{
id: 1,
question: "What are the key benefits of the described technology?",
answer: "No answer available",
type: "single_shot",
},
{
id: 2,
question:
"Based on the context about machine learning frameworks, how does TensorFlow compare to PyTorch in terms of deployment capabilities?",
answer: "No answer available",
type: "multi_hop",
},
];
const handleEvaluationClick = () => {
if (onStartEvaluation) {
onStartEvaluation();
}
};
const handleDownloadClick = async () => {
if (!sessionId) return;
setIsDownloading(true);
try {
// Requête pour télécharger le dataset
const downloadUrl = `http://localhost:3001/download-dataset/${sessionId}`;
// Créer un élément a temporaire pour déclencher le téléchargement
const link = document.createElement("a");
link.href = downloadUrl;
link.setAttribute("download", `yourbench_${sessionId}_dataset.zip`);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error) {
console.error("Erreur lors du téléchargement du dataset:", error);
alert("Erreur lors du téléchargement. Veuillez réessayer.");
} finally {
setIsDownloading(false);
}
};
return (
<>
Benchmark Created Successfully
:
}
onClick={handleDownloadClick}
disabled={isDownloading || !sessionId}
>
{isDownloading ? "Downloading..." : "Download Benchmark"}
Your benchmark has been generated. Here are some example questions:
{questions.map((q, index) => (
{q.type === "multi_hop"
? "Multi-hop Question"
: "Single-shot Question"}
Question: {q.question}
Answer: {q.answer || "No answer available"}
))}
}
onClick={handleEvaluationClick}
>
Start Evaluation
>
);
};
export default BenchmarkDisplay;