import React, { useState, useEffect } from 'react' import API from '../API' import LoadingSpinner from './LoadingSpinner' import ImageGallery from './ImageGallery' import AudioGallery from './AudioGallery' import VideoGallery from './VideoGallery' interface ExamplesProps { fileType: 'image' | 'audio' | 'video' } // Move ExamplesData type export to allow import in Galleries.tsx export type ExamplesData = { image_url: string audio_url?: string video_url?: string name: string metadata: { [key: string]: string | boolean } } const Examples = ({ fileType }: ExamplesProps) => { const [examples, setExamples] = useState<{ [model: string]: { [attack: string]: ExamplesData[] } }>({}) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const [selectedModel, setSelectedModel] = useState(null) const [selectedAttack, setSelectedAttack] = useState(null) useEffect(() => { setLoading(true) setError(null) API.fetchExamplesByType(fileType) .then((data) => { // data is a dictionary from {[model]: {[attack]: {image_url, audio_url, video_url, description}}} setExamples(data) // get the first model and attack if available const models = Object.keys(data) if (models.length > 0) { setSelectedModel(models[0]) const attacks = Object.keys(data[models[0]]) if (attacks.length > 0) { setSelectedAttack(attacks[0]) // Set the first attack of the first model } else { setSelectedAttack(null) // No attacks available } } else { setSelectedModel(null) setSelectedAttack(null) // No models available } // Reset loading state setLoading(false) }) .catch((err) => { setError(err.message) setLoading(false) }) }, [fileType]) if (loading) { return } return (
Model
{selectedModel && (
Attack
)}
{error &&

Error: {error}

} {selectedModel && selectedAttack && fileType === 'image' && ( )} {selectedModel && selectedAttack && fileType === 'audio' && ( )} {selectedModel && selectedAttack && fileType === 'video' && ( )}
) } export default Examples