import React from 'react'; import { Paper, Typography, Box, List, ListItem, ListItemText, Divider, Grid, Chip } from '@material-ui/core'; import VectorDBActions from './VectorDBActions'; import { makeStyles } from '@material-ui/core/styles'; const useStyles = makeStyles((theme) => ({ paper: { padding: theme.spacing(2) }, marginBottom: { marginBottom: theme.spacing(2) }, resultImage: { maxWidth: '100%', maxHeight: '400px', objectFit: 'contain' }, dividerMargin: { margin: `${theme.spacing(2)}px 0` }, chipContainer: { display: 'flex', gap: theme.spacing(1), flexWrap: 'wrap' } })); const ResultDisplay = ({ results }) => { const classes = useStyles(); if (!results) return null; const { model, data } = results; // Helper to format times nicely const formatTime = (ms) => { if (ms === undefined || ms === null || isNaN(ms)) return '-'; const num = Number(ms); if (num < 1000) return `${num.toFixed(2)} ms`; return `${(num / 1000).toFixed(2)} s`; }; // Check if there's an error if (data.error) { return ( {data.error} ); } // Display performance info const renderPerformanceInfo = () => { if (!data.performance) return null; return ( Inference time: {formatTime(data.performance.inference_time)} on {data.performance.device} ); }; // Render for YOLO and DETR (object detection) if (model === 'yolo' || model === 'detr') { return ( {model === 'yolo' ? 'YOLOv8' : 'DETR'} Detection Results {data.image && ( Detection Result Detection Result )} Detected Objects: {data.detections && data.detections.length > 0 ? ( {data.detections.map((detection, index) => ( {detection.class} } secondary={`Bounding Box: [${detection.bbox.join(', ')}]`} /> {index < data.detections.length - 1 && } ))} ) : ( No objects detected )} {renderPerformanceInfo()} {/* Vector DB Actions for Object Detection */} ); } // Render for ViT (classification) if (model === 'vit') { return ( ViT Classification Results Top Predictions: {data.top_predictions && data.top_predictions.length > 0 ? ( {data.top_predictions.map((prediction, index) => ( {prediction.rank}. {prediction.class} } /> {index < data.top_predictions.length - 1 && } ))} ) : ( No classifications available )} {renderPerformanceInfo()} {/* Vector DB Actions for ViT Classification */} ); } return null; }; export default ResultDisplay;