let models = []; let currentPage = 1; const modelsPerPage = 12; // DOM Elements const modelGrid = document.getElementById('modelGrid'); const configSection = document.getElementById('configSection'); const configList = document.getElementById('configList'); const selectedModelId = document.getElementById('selectedModelId'); const configModelTitle = document.getElementById('configModelTitle'); const noConfig = document.getElementById('noConfig'); const prevPageBtn = document.getElementById('prevPage'); const nextPageBtn = document.getElementById('nextPage'); const pageInfo = document.getElementById('pageInfo'); const searchButton = document.getElementById('searchButton'); const modelIdSearch = document.getElementById('modelIdSearch'); const closeConfig = document.getElementById('closeConfig'); const loadingModels = document.getElementById('loadingModels'); const loadingConfig = document.getElementById('loadingConfig'); // Fetch models from the API async function fetchModels() { loadingModels.style.display = 'block'; try { const response = await fetch('/api/models'); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log('Fetched models:', data); models = data || []; renderModels(); updatePagination(); } catch (error) { console.error('Error fetching models:', error); modelGrid.innerHTML = `

Error loading models

${error.message}

`; } finally { loadingModels.style.display = 'none'; } } // Fetch configurations for a specific model async function showModelConfigurations(modelId) { configSection.style.display = 'block'; selectedModelId.textContent = modelId; configList.innerHTML = ''; loadingConfig.style.display = 'block'; noConfig.style.display = 'none'; try { const response = await fetch(`/api/models/${modelId}`); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); const configs = data.configurations; if (!configs || configs.length === 0) { noConfig.style.display = 'block'; configList.innerHTML = ''; } else { configs.forEach((config) => { const configCard = document.createElement('div'); configCard.className = 'config-card'; let detailsHtml = `
Num Cores: ${config.num_cores}
Auto Cast Type: ${config.auto_cast_type}
Batch Size: ${config.batch_size}
Sequence Length: ${config.sequence_length}
Compiler Type: ${config.compiler_type}
Compiler Version: ${config.compiler_version}
`; configCard.innerHTML = detailsHtml; configList.appendChild(configCard); }); } } catch (error) { console.error('Error fetching configurations:', error); noConfig.style.display = 'block'; noConfig.innerHTML = `

Error loading configurations

Failed to fetch configurations. Please try again later.

`; configList.innerHTML = ''; } finally { loadingConfig.style.display = 'none'; } } // Initialize the page document.addEventListener('DOMContentLoaded', () => { fetchModels(); // Add event listeners document.getElementById('searchButton').addEventListener('click', handleSearch); document.getElementById('prevPage').addEventListener('click', goToPrevPage); document.getElementById('nextPage').addEventListener('click', goToNextPage); document.getElementById('closeConfig').addEventListener('click', () => { document.getElementById('configSection').style.display = 'none'; }); }); function renderModels() { loadingModels.style.display = 'block'; modelGrid.innerHTML = ''; // Simulate API delay setTimeout(() => { const startIdx = (currentPage - 1) * modelsPerPage; const endIdx = startIdx + modelsPerPage; // Sort models alphabetically by title (case-insensitive) const sortedModels = [...models].sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()) ); const paginatedModels = sortedModels.slice(startIdx, endIdx); if (paginatedModels.length === 0) { modelGrid.innerHTML = `

No models available

There are currently no models to display.

`; } else { paginatedModels.forEach(model => { const modelCard = document.createElement('div'); modelCard.className = 'model-card'; modelCard.innerHTML = `

${model.name}

Architecture: ${model.type}

`; modelCard.addEventListener('click', () => showModelConfigurations(model.id)); modelGrid.appendChild(modelCard); }); } loadingModels.style.display = 'none'; }, 500); } function getModelIcon(type) { switch(type.toLowerCase()) { case 'regression': return 'fa-chart-line'; case 'classification': return 'fa-tags'; case 'ensemble': return 'fa-layer-group'; case 'forecasting': return 'fa-calendar-alt'; case 'clustering': return 'fa-object-group'; default: return 'fa-cube'; } } function handleSearch() { const searchTerm = modelIdSearch.value.trim(); if (!searchTerm) { alert('Please enter a Model ID'); return; } // Show configurations for the searched model showModelConfigurations(searchTerm); } function updatePagination() { const totalPages = Math.ceil(models.length / modelsPerPage); prevPageBtn.disabled = currentPage <= 1; nextPageBtn.disabled = currentPage >= totalPages; pageInfo.textContent = `Page ${currentPage} of ${totalPages}`; } function goToPrevPage() { if (currentPage > 1) { currentPage--; renderModels(); updatePagination(); } } function goToNextPage() { const totalPages = Math.ceil(models.length / modelsPerPage); if (currentPage < totalPages) { currentPage++; renderModels(); updatePagination(); } } function createConfigurationElement(config) { const configElement = document.createElement('div'); configElement.className = 'config-item'; // Add your configuration content here, but skip the title // For example: configElement.innerHTML = `
`; return configElement; }