Add debug logging and better error handling for search
Browse files197 unmodified lines198199200201202203444 unmodified lines64864965065165265365418 unmodified lines67367467567667767867915 unmodified lines69569669769869970019 unmodified lines72072172272372472554 unmodified lines78078178278378478578678778878979079179279379479579679779879980015 unmodified lines8168178188198208218228238248258268273 unmodified lines83183283383483583683783883984084110 unmodified lines85285385485585685785813 unmodified lines8728738748758768778788798808818828833 unmodified lines8878888898908918928938948958968978 unmodified lines90690790890991091191291391491591691791891992092116 unmodified lines9389399409419429433 unmodified lines9479489499509519529531 unmodified line95595695795895996096196296396496596696796896997016 unmodified lines9879889899909919923 unmodified lines996997998999100010011002129 unmodified lines1132113311341135113611371138197 unmodified linesborder-radius: 8px;margin-top: 10px;}</style></head><body>444 unmodified lines<div class="col-md-8"><div class="search-box"><i class="bi bi-search"></i><input type="text" class="form-control" id="models-page-search" placeholder="Search models..."></div></div><div class="col-md-4">18 unmodified lines<div class="col-md-8"><div class="search-box"><i class="bi bi-search"></i><input type="text" class="form-control" id="datasets-page-search" placeholder="Search datasets..."></div></div><div class="col-md-4">15 unmodified lines</div><div class="card-body"><p class="text-muted">Configure your training environment</p></div></div></div>19 unmodified lineslet selectedModel = null;let selectedDataset = null;function showSection(sectionId) {document.querySelectorAll('.section').forEach(s => s.style.display = 'none');document.getElementById('section-' + sectionId).style.display = 'block';54 unmodified linesif (!selectedTask) return;try {// Load model recommendationsconst modelRecRes = await fetch(API_BASE + '/models/recommend/' + selectedTask);if (modelRecRes.ok) {const modelRecs = await modelRecRes.json();const modelContainer = document.getElementById('model-recommendations');if (modelRecs && modelRecs.length > 0) {modelContainer.innerHTML = '<h6 class="mb-2">Recommended Models:</h6><div class="row g-2">' +modelRecs.slice(0, 4).map(m => '<div class="col-md-3"><div class="card task-card" onclick="selectModel(\'' + m.model_id + '\')"><div class="card-body py-2"><small class="fw-bold">' + m.model_id + '</small><br><small class="text-muted">' + (m.size || '') + '</small></div></div></div>').join('') + '</div>';}}// Load dataset recommendationsconst datasetRecRes = await fetch(API_BASE + '/datasets/recommend/' + selectedTask);if (datasetRecRes.ok) {const datasetRecs = await datasetRecRes.json();const datasetContainer = document.getElementById('dataset-recommendations');if (datasetRecs && datasetRecs.length > 0) {datasetContainer.innerHTML = '<h6 class="mb-2">Recommended Datasets:</h6><div class="row g-2">' +15 unmodified linescontainer.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';try {const res = await fetch(API_BASE + '/models/search?query=' + encodeURIComponent(query) + '&limit=12');if (!res.ok) {throw new Error('Search failed: ' + res.status);}const data = await res.json();console.log('Model search results:', data);renderModelResults(data);} catch (error) {console.error('Error searching models:', error);3 unmodified linesfunction renderModelResults(models) {const container = document.getElementById('model-results');if (!models || models.length === 0) {container.innerHTML = '<div class="col-12 text-center text-muted py-3"><i class="bi bi-search fs-1 d-block mb-2"></i>No models found. Try a different search term.</div>';return;}container.innerHTML = models.slice(0, 12).map(model => '<div class="col-md-3"><div class="card task-card" onclick="selectModel(\'' + (model.id || model.model_id) + '\')"><div class="card-body py-2"><small class="fw-bold">' + (model.id || model.model_id) + '</small><br><small class="text-muted">' + formatBytes(model.size_bytes || model.downloads || 0) + '</small></div></div></div>').join('');}async function selectModel(modelId) {10 unmodified linesconst res = await fetch(API_BASE + '/models/info/' + encodeURIComponent(modelId));if (res.ok) {const info = await res.json();container.innerHTML = '<div class="card"><div class="card-body"><h6>' + info.model_id + '</h6><div class="row"><div class="col-6"><small class="text-muted">Downloads:</small></div><div class="col-6 text-end"><small>' + (info.downloads?.toLocaleString() || 'N/A') + '</small></div></div><div class="row"><div class="col-6"><small class="text-muted">Architecture:</small></div><div class="col-6 text-end"><small>' + (info.architectures?.[0] || info.architecture || 'Unknown') + '</small></div></div><div class="row"><div class="col-6"><small class="text-muted">Pipeline Tag:</small></div><div class="col-6 text-end"><small>' + (info.pipeline_tag || 'N/A') + '</small></div></div></div></div>';} else {container.innerHTML = '<div class="card"><div class="card-body"><small class="text-muted">Selected: ' + modelId + '</small></div></div>';}13 unmodified linescontainer.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';try {const res = await fetch(API_BASE + '/datasets/search?query=' + encodeURIComponent(query) + '&limit=12');if (!res.ok) {throw new Error('Search failed: ' + res.status);}const data = await res.json();console.log('Dataset search results:', data);renderDatasetResults(data);} catch (error) {console.error('Error searching datasets:', error);3 unmodified linesfunction renderDatasetResults(datasets) {const container = document.getElementById('dataset-results');if (!datasets || datasets.length === 0) {container.innerHTML = '<div class="col-12 text-center text-muted py-3"><i class="bi bi-search fs-1 d-block mb-2"></i>No datasets found. Try a different search term.</div>';return;}container.innerHTML = datasets.slice(0, 12).map(ds => '<div class="col-md-3"><div class="card task-card" onclick="selectDataset(\'' + ds.id + '\')"><div class="card-body py-2"><small class="fw-bold">' + ds.id + '</small><br><small class="text-muted">' + (ds.downloads?.toLocaleString() || 0) + ' downloads</small></div></div></div>').join('');}function selectDataset(datasetId) {8 unmodified linescontainer.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';try {const res = await fetch(API_BASE + '/models/popular?limit=20');if (res.ok) {const data = await res.json();renderModelsPage(data);} else {container.innerHTML = '<div class="col-12 text-center text-muted">No models found</div>';}} catch (error) {console.error('Error loading popular models:', error);container.innerHTML = '<div class="col-12 text-center text-muted">Error loading models</div>';}}16 unmodified lines}} catch (error) {console.error('Error searching models:', error);}}3 unmodified linescontainer.innerHTML = '<div class="col-12 text-center text-muted py-3">No models found</div>';return;}container.innerHTML = models.map(m => '<div class="col-md-3"><div class="card model-card"><div class="card-body"><h6>' + (m.id || m.model_id) + '</h6><small class="text-muted d-block">' + (m.pipeline_tag || 'Unknown') + '</small><small class="text-muted">' + (m.downloads?.toLocaleString() || 0) + ' downloads</small></div></div></div>').join('');}async function loadPopularDatasets() {1 unmodified linecontainer.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';try {const res = await fetch(API_BASE + '/datasets/popular?limit=20');if (res.ok) {const data = await res.json();renderDatasetsPage(data);} else {container.innerHTML = '<div class="col-12 text-center text-muted">No datasets found</div>';}} catch (error) {console.error('Error loading popular datasets:', error);container.innerHTML = '<div class="col-12 text-center text-muted">Error loading datasets</div>';}}16 unmodified lines}} catch (error) {console.error('Error searching datasets:', error);}}3 unmodified linescontainer.innerHTML = '<div class="col-12 text-center text-muted py-3">No datasets found</div>';return;}container.innerHTML = datasets.map(d => '<div class="col-md-3"><div class="card model-card"><div class="card-body"><h6>' + (d.id || d.dataset_id) + '</h6><small class="text-muted d-block">' + (d.description?.substring(0, 50) || 'No description') + '</small><small class="text-muted">' + (d.downloads?.toLocaleString() || 0) + ' downloads</small></div></div></div>').join('');}async function loadJobs() {129 unmodified lineswindow.location.href = API_BASE + '/jobs/' + jobId + '/download';}document.addEventListener('DOMContentLoaded', () => {loadDashboard();setInterval(loadDashboard, 30000);});197 unmodified lines198199200201202203204205206207208209210211212444 unmodified lines65765865966066166266318 unmodified lines68268368468568668768815 unmodified lines70470570670770870971071171271371471571671771871972072172272319 unmodified lines74374474574674774874975075175275354 unmodified lines80880981081181281381481581681781881982082182282382482582682782882983083183283383415 unmodified lines8508518528538548558568578588598608618628638648658668673 unmodified lines87187287387487587687787887988088188288388488588610 unmodified lines89789889990090190290313 unmodified lines9179189199209219229239249259269279289299309319329339343 unmodified lines9389399409419429439449459469479489499509519529538 unmodified lines96296396496596696796896997097197297397497597697797897998016 unmodified lines99799899910001001100210033 unmodified lines1007100810091010101110121013101410151016101710181 unmodified line102010211022102310241025102610271028102910301031103210331034103510361037103816 unmodified lines10551056105710581059106010613 unmodified lines10651066106710681069107010711072107310741075129 unmodified lines120512061207120812091210121112121213121412151216121712181219122012211222122312241225197 unmodified linesborder-radius: 8px;margin-top: 10px;}.debug-panel {background: #f8f9fa;border: 1px solid #dee2e6;border-radius: 8px;padding: 10px;margin-top: 10px;font-family: monospace;font-size: 0.8rem;}</style></head><body>444 unmodified lines<div class="col-md-8"><div class="search-box"><i class="bi bi-search"></i><input type="text" class="form-control" id="models-page-search" placeholder="Search models..." onkeypress="if(event.key==='Enter')searchModelsPage()"></div></div><div class="col-md-4">18 unmodified lines<div class="col-md-8"><div class="search-box"><i class="bi bi-search"></i><input type="text" class="form-control" id="datasets-page-search" placeholder="Search datasets..." onkeypress="if(event.key==='Enter')searchDatasetsPage()"></div></div><div class="col-md-4">15 unmodified lines</div><div class="card-body"><p class="text-muted">Configure your training environment</p><div class="row g-3"><div class="col-md-6"><label class="form-label">HuggingFace Token</label><input type="password" class="form-control" id="hf-token" placeholder="hf_..."><small class="text-muted">Required for pushing models to Hub and accessing gated models</small></div><div class="col-md-6"><label class="form-label">WANDB API Key (Optional)</label><input type="password" class="form-control" id="wandb-key" placeholder="Optional for experiment tracking"></div></div><button class="btn btn-primary mt-3" onclick="saveSettings()"><i class="bi bi-save me-1"></i>Save Settings</button></div></div></div>19 unmodified lineslet selectedModel = null;let selectedDataset = null;// Debug helperfunction debug(message, data) {console.log('[DEBUG]', message, data || '');}function showSection(sectionId) {document.querySelectorAll('.section').forEach(s => s.style.display = 'none');document.getElementById('section-' + sectionId).style.display = 'block';54 unmodified linesif (!selectedTask) return;try {debug('Loading recommendations for task:', selectedTask);// Load model recommendationsconst modelRecRes = await fetch(API_BASE + '/models/recommend/' + selectedTask);debug('Model recommendations response status:', modelRecRes.status);if (modelRecRes.ok) {const modelRecs = await modelRecRes.json();debug('Model recommendations:', modelRecs);const modelContainer = document.getElementById('model-recommendations');if (modelRecs && modelRecs.length > 0) {modelContainer.innerHTML = '<h6 class="mb-2">Recommended Models:</h6><div class="row g-2">' +modelRecs.slice(0, 4).map(m => '<div class="col-md-3"><div class="card task-card" onclick="selectModel(\'' + m.model_id + '\')"><div class="card-body py-2"><small class="fw-bold">' + m.model_id + '</small><br><small class="text-muted">VRAM: ' + (m.estimated_vram || 'N/A') + '</small></div></div></div>').join('') + '</div>';}}// Load dataset recommendationsconst datasetRecRes = await fetch(API_BASE + '/datasets/recommend/' + selectedTask);debug('Dataset recommendations response status:', datasetRecRes.status);if (datasetRecRes.ok) {const datasetRecs = await datasetRecRes.json();debug('Dataset recommendations:', datasetRecs);const datasetContainer = document.getElementById('dataset-recommendations');if (datasetRecs && datasetRecs.length > 0) {datasetContainer.innerHTML = '<h6 class="mb-2">Recommended Datasets:</h6><div class="row g-2">' +15 unmodified linescontainer.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';try {const url = API_BASE + '/models/search?query=' + encodeURIComponent(query) + '&limit=12';debug('Searching models:', url);const res = await fetch(url);debug('Search response status:', res.status);if (!res.ok) {const errorText = await res.text();debug('Search error response:', errorText);throw new Error('Search failed: ' + res.status + ' - ' + errorText);}const data = await res.json();debug('Search results:', data);renderModelResults(data);} catch (error) {console.error('Error searching models:', error);3 unmodified linesfunction renderModelResults(models) {const container = document.getElementById('model-results');debug('Rendering model results:', models);if (!models || models.length === 0) {container.innerHTML = '<div class="col-12 text-center text-muted py-3"><i class="bi bi-search fs-1 d-block mb-2"></i>No models found. Try a different search term.</div>';return;}container.innerHTML = models.slice(0, 12).map(model => {const id = model.id || model.model_id || model.modelId || model.name || 'unknown';const downloads = model.downloads || 0;return '<div class="col-md-3"><div class="card task-card" onclick="selectModel(\'' + id + '\')"><div class="card-body py-2"><small class="fw-bold text-truncate d-block">' + id + '</small><small class="text-muted">' + downloads.toLocaleString() + ' downloads</small></div></div></div>';}).join('');}async function selectModel(modelId) {10 unmodified linesconst res = await fetch(API_BASE + '/models/info/' + encodeURIComponent(modelId));if (res.ok) {const info = await res.json();container.innerHTML = '<div class="card"><div class="card-body"><h6>' + (info.id || modelId) + '</h6><div class="row"><div class="col-6"><small class="text-muted">Downloads:</small></div><div class="col-6 text-end"><small>' + (info.downloads?.toLocaleString() || 'N/A') + '</small></div></div><div class="row"><div class="col-6"><small class="text-muted">Pipeline:</small></div><div class="col-6 text-end"><small>' + (info.pipeline_tag || 'N/A') + '</small></div></div><div class="row"><div class="col-6"><small class="text-muted">Library:</small></div><div class="col-6 text-end"><small>' + (info.library_name || 'Unknown') + '</small></div></div></div></div>';} else {container.innerHTML = '<div class="card"><div class="card-body"><small class="text-muted">Selected: ' + modelId + '</small></div></div>';}13 unmodified linescontainer.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';try {const url = API_BASE + '/datasets/search?query=' + encodeURIComponent(query) + '&limit=12';debug('Searching datasets:', url);const res = await fetch(url);debug('Dataset search response status:', res.status);if (!res.ok) {const errorText = await res.text();debug('Dataset search error response:', errorText);throw new Error('Search failed: ' + res.status + ' - ' + errorText);}const data = await res.json();debug('Dataset search results:', data);renderDatasetResults(data);} catch (error) {console.error('Error searching datasets:', error);3 unmodified linesfunction renderDatasetResults(datasets) {const container = document.getElementById('dataset-results');debug('Rendering dataset results:', datasets);if (!datasets || datasets.length === 0) {container.innerHTML = '<div class="col-12 text-center text-muted py-3"><i class="bi bi-search fs-1 d-block mb-2"></i>No datasets found. Try a different search term.</div>';return;}container.innerHTML = datasets.slice(0, 12).map(ds => {const id = ds.id || ds.dataset_id || ds.datasetId || ds.name || 'unknown';const downloads = ds.downloads || 0;return '<div class="col-md-3"><div class="card task-card" onclick="selectDataset(\'' + id + '\')"><div class="card-body py-2"><small class="fw-bold text-truncate d-block">' + id + '</small><small class="text-muted">' + downloads.toLocaleString() + ' downloads</small></div></div></div>';}).join('');}function selectDataset(datasetId) {8 unmodified linescontainer.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';try {debug('Loading popular models...');const res = await fetch(API_BASE + '/models/popular?limit=20');debug('Popular models response:', res.status);if (res.ok) {const data = await res.json();debug('Popular models data:', data);renderModelsPage(data);} else {container.innerHTML = '<div class="col-12 text-center text-muted">No models found</div>';}} catch (error) {console.error('Error loading popular models:', error);container.innerHTML = '<div class="col-12 text-center text-muted">Error loading models: ' + error.message + '</div>';}}16 unmodified lines}} catch (error) {console.error('Error searching models:', error);container.innerHTML = '<div class="col-12 text-center text-muted">Error: ' + error.message + '</div>';}}3 unmodified linescontainer.innerHTML = '<div class="col-12 text-center text-muted py-3">No models found</div>';return;}container.innerHTML = models.map(m => {const id = m.id || m.model_id || m.modelId || 'unknown';const tag = m.pipeline_tag || m.task || 'unknown';const downloads = m.downloads || 0;return '<div class="col-md-3"><div class="card model-card"><div class="card-body"><h6>' + id + '</h6><small class="text-muted d-block">' + tag + '</small><small class="text-muted">' + downloads.toLocaleString() + ' downloads</small></div></div></div>';}).join('');}async function loadPopularDatasets() {1 unmodified linecontainer.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';try {debug('Loading popular datasets...');const res = await fetch(API_BASE + '/datasets/popular?limit=20');debug('Popular datasets response:', res.status);if (res.ok) {const data = await res.json();debug('Popular datasets data:', data);renderDatasetsPage(data);} else {container.innerHTML = '<div class="col-12 text-center text-muted">No datasets found</div>';}} catch (error) {console.error('Error loading popular datasets:', error);container.innerHTML = '<div class="col-12 text-center text-muted">Error loading datasets: ' + error.message + '</div>';}}16 unmodified lines}} catch (error) {console.error('Error searching datasets:', error);container.innerHTML = '<div class="col-12 text-center text-muted">Error: ' + error.message + '</div>';}}3 unmodified linescontainer.innerHTML = '<div class="col-12 text-center text-muted py-3">No datasets found</div>';return;}container.innerHTML = datasets.map(d => {const id = d.id || d.dataset_id || d.datasetId || d.name || 'unknown';const downloads = d.downloads || 0;return '<div class="col-md-3"><div class="card model-card"><div class="card-body"><h6>' + id + '</h6><small class="text-muted">' + downloads.toLocaleString() + ' downloads</small></div></div></div>';}).join('');}async function loadJobs() {129 unmodified lineswindow.location.href = API_BASE + '/jobs/' + jobId + '/download';}function saveSettings() {const hfToken = document.getElementById('hf-token').value;const wandbKey = document.getElementById('wandb-key').value;localStorage.setItem('hf_token', hfToken);localStorage.setItem('wandb_key', wandbKey);alert('Settings saved!');}document.addEventListener('DOMContentLoaded', () => {// Load saved settingsconst savedToken = localStorage.getItem('hf_token');const savedWandb = localStorage.getItem('wandb_key');if (savedToken) document.getElementById('hf-token').value = savedToken;if (savedWandb) document.getElementById('wandb-key').value = savedWandb;loadDashboard();setInterval(loadDashboard, 30000);});
app/templates/dashboard.html+103-16