import Image from "next/image"; import clsx from "clsx"; import RadialProgressBar from "./RadialProgressBar"; import { AIDetectionAttributes } from "@/interfaces/exam"; import { Tooltip } from 'react-tooltip'; import SegmentedProgressBar from "./SegmentedProgressBar"; // Colors and texts scrapped from gpt's zero react bundle const AIDetection: React.FC = ({ predicted_class, confidence_category, class_probabilities, sentences }) => { const probabilityTooltipContent = ` Encoach's deep learning model predicts the
probability this text has been entirely
generated by AI. For instance, a 40% AI
probability does not indicate that the text
contains 40% AI-written content. Rather, it
indicates the text is more likely to be partially
human written than be entirely AI-written. `; const confidenceTooltipContent = ` Confidence scores are a safeguard to better
understand AI identification results. Encoach
trained it's deep learning model on a diverse
dataset of millions of human and AI-written
documents. Green scores indicate that you can scan
with confidence that the model has classified
many similar documents with high accuracy.
Red scores indicate that this text is dissimilar
to the ones in their training set, which can impact
the model's accuracy, and to proceed with caution. `; const confidenceKeywords = ["moderately", "highly", "confident", "uncertain"]; var confidence = { low: { ai: "Encoach is uncertain about this text. If Encoach had to classify it, it would be considered", human: "Encoach is uncertain about this text. If Encoach had to classify it, it would likely be considered", mixed: "Encoach is uncertain about this text. If Encoach had to classify it, it would likely be a" }, medium: { ai: "Encoach is moderately confident this text was", human: "Encoach is moderately confident this text is entirely", mixed: "Encoach is moderately confident this text is a" }, high: { ai: "Encoach is highly confident this text was", human: "Encoach is highly confident this text is entirely", mixed: "Encoach is highly confident this text is a" } } var classPrediction = { ai: { background: "bg-ai-detection-result-ai-bg", color: "text-ai-detection-result-ai", text: "ai generated" }, mixed: { background: "bg-ai-detection-result-mixed-bg", color: "text-ai-detection-result-mixed", text: "mix of ai and human" }, human: { background: "bg-ai-detection-result-human-bg", color: "text-ai-detection-result-human", text: "human" } } const segments = [ { percentage: Math.round(class_probabilities["human"] * 100), subtitle: 'human', color: "ai-detection-result-human" }, { percentage: Math.round(class_probabilities["mixed"] * 100), subtitle: 'mixed', color: "ai-detection-result-mixed" }, { percentage: Math.round(class_probabilities["ai"] * 100), subtitle: 'ai', color: "ai-detection-result-ai" } ]; const styleConfidenceText = (text: string): [string, string[]] => { const keywords: string[] = []; const styledText = text.split(" ").map(word => { if (confidenceKeywords.includes(word)) { keywords.push(word); return `${word}`; } return word }).join(" "); return [styledText, keywords]; }; const confidenceText = confidence[confidence_category][predicted_class]; const [styledText, keywords] = styleConfidenceText(confidenceText); const tooltipStyle = { "backgroundColor": "rgb(255, 255, 255)", "color": "#8992B1", boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)', borderRadius: '0.125rem' } const highestProbability = Math.max(class_probabilities["ai"], class_probabilities["human"], class_probabilities["mixed"]); const spanTextColor = highestProbability === class_probabilities["ai"] ? "#f4bf4f" : highestProbability === class_probabilities["human"] ? "#50c08a" : "#93aafb"; let spanClassName = highestProbability === class_probabilities["ai"] ? "text-ai-detection-result-ai" : highestProbability === class_probabilities["human"] ? "text-ai-detection-result-human" : "text-ai-detection-result-mixed"; spanClassName = `${spanClassName} font-bold text-lg` const percentage = Math.round(highestProbability * 100) const hasHighlightedForAI = sentences.some(item => item.highlight_sentence_for_ai); return ( <>

Encoach Detection Results

Text Classification

{`${Math.round(class_probabilities["ai"] * 100)}%`} Probability AI generated Probability Tooltip
{keywords.join(' ')} Probability Tooltip

Probability Breakdown

{classPrediction[predicted_class]['text']}
{(hasHighlightedForAI &&
Sentences that are likely written by AI are highlighted.
)}
{sentences.map((item, index) => ( {item.sentence}{' '} ))}
) } export default AIDetection;