File size: 8,355 Bytes
deb3471
 
ea6172d
deb3471
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e0174a0
 
 
deb3471
e0174a0
 
deb3471
 
 
 
e0174a0
 
 
 
 
 
 
deb3471
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea6172d
deb3471
 
 
ea6172d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
deb3471
 
 
ea6172d
 
deb3471
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea6172d
 
 
 
 
 
 
deb3471
 
 
 
 
 
 
 
 
 
 
 
 
 
ea6172d
deb3471
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea6172d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
deb3471
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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 = `
            <div class="empty-state">
                <i class="fas fa-exclamation-circle"></i>
                <h4>Error loading models</h4>
                <p>${error.message}</p>
            </div>
        `;
    } 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 = `
                    <div class="config-content">
                        <div class="detail-item">
                            <strong>Num Cores:</strong>
                            <span>${config.num_cores}</span>
                        </div>
                        <div class="detail-item">
                            <strong>Auto Cast Type:</strong>
                            <span>${config.auto_cast_type}</span>
                        </div>
                        <div class="detail-item">
                            <strong>Batch Size:</strong>
                            <span>${config.batch_size}</span>
                        </div>
                        <div class="detail-item">
                            <strong>Sequence Length:</strong>
                            <span>${config.sequence_length}</span>
                        </div>
                        <div class="detail-item">
                            <strong>Compiler Type:</strong>
                            <span>${config.compiler_type}</span>
                        </div>
                        <div class="detail-item">
                            <strong>Compiler Version:</strong>
                            <span>${config.compiler_version}</span>
                        </div>
                    </div>
                `;
                
                configCard.innerHTML = detailsHtml;
                configList.appendChild(configCard);
            });
        }
    } catch (error) {
        console.error('Error fetching configurations:', error);
        noConfig.style.display = 'block';
        noConfig.innerHTML = `
            <i class="fas fa-exclamation-circle"></i>
            <h4>Error loading configurations</h4>
            <p>Failed to fetch configurations. Please try again later.</p>
        `;
        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 = `
                <div class="empty-state">
                    <i class="fas fa-exclamation-circle"></i>
                    <h4>No models available</h4>
                    <p>There are currently no models to display.</p>
                </div>
            `;
        } else {
            paginatedModels.forEach(model => {
                const modelCard = document.createElement('div');
                modelCard.className = 'model-card';
                modelCard.innerHTML = `
                    <h3><strong>${model.name}</strong></h3>
                    <p class="subtitle">Architecture: ${model.type}</p>
                `;
                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 = `
        <div class="config-content">
            <!-- Your configuration details here -->
        </div>
    `;
    
    return configElement;
}