Spaces:
Sleeping
Sleeping
Download static/js/script.js from Nausad/Data2Model: direct link, hf CLI and curl.
- Browser
- Download file 9.29 kB
-
https://huggingface.co/spaces/Nausad/Data2Model/resolve/main/static/js/script.js
- Command line
-
hf download hf://spaces/Nausad/Data2Model/static/js/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Nausad/Data2Model/resolve/main/static/js/script.js
9.29 kB
| // Data2Model JavaScript | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize tooltips | |
| var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); | |
| var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { | |
| return new bootstrap.Tooltip(tooltipTriggerEl); | |
| }); | |
| // File upload validation | |
| const fileInput = document.getElementById('file'); | |
| if (fileInput) { | |
| fileInput.addEventListener('change', function(e) { | |
| const file = e.target.files[0]; | |
| if (file) { | |
| // Check file extension | |
| const allowedExtensions = ['csv', 'xlsx', 'xls', 'json']; | |
| const fileName = file.name.toLowerCase(); | |
| const fileExtension = fileName.split('.').pop(); | |
| if (!allowedExtensions.includes(fileExtension)) { | |
| alert('Invalid file type. Please upload CSV, Excel, or JSON files only.'); | |
| fileInput.value = ''; | |
| return; | |
| } | |
| // Show file info | |
| console.log('File selected:', file.name, 'Size:', (file.size / 1024 / 1024).toFixed(2) + ' MB'); | |
| } | |
| }); | |
| } | |
| // Form submission with loading indicator | |
| const forms = document.querySelectorAll('form'); | |
| forms.forEach(form => { | |
| form.addEventListener('submit', function(e) { | |
| const submitBtn = form.querySelector('button[type="submit"]'); | |
| if (submitBtn) { | |
| // Disable button and show loading | |
| submitBtn.disabled = true; | |
| const originalText = submitBtn.innerHTML; | |
| submitBtn.innerHTML = '<span class="loading"></span> Processing...'; | |
| // Re-enable after 2 seconds if form doesn't submit | |
| setTimeout(() => { | |
| if (submitBtn.disabled) { | |
| submitBtn.disabled = false; | |
| submitBtn.innerHTML = originalText; | |
| } | |
| }, 60000); // 60 seconds timeout | |
| } | |
| }); | |
| }); | |
| // Auto-hide alerts after 5 seconds | |
| const alerts = document.querySelectorAll('.alert'); | |
| alerts.forEach(alert => { | |
| setTimeout(() => { | |
| const bsAlert = new bootstrap.Alert(alert); | |
| bsAlert.close(); | |
| }, 5000); | |
| }); | |
| // Smooth scroll for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| const target = document.querySelector(this.getAttribute('href')); | |
| if (target) { | |
| target.scrollIntoView({ | |
| behavior: 'smooth', | |
| block: 'start' | |
| }); | |
| } | |
| }); | |
| }); | |
| // Add fade-in animation to cards | |
| const cards = document.querySelectorAll('.card'); | |
| const observerOptions = { | |
| threshold: 0.1, | |
| rootMargin: '0px 0px -50px 0px' | |
| }; | |
| const observer = new IntersectionObserver(function(entries) { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| entry.target.classList.add('fade-in'); | |
| observer.unobserve(entry.target); | |
| } | |
| }); | |
| }, observerOptions); | |
| cards.forEach(card => { | |
| observer.observe(card); | |
| }); | |
| // Target column change handler | |
| const targetColumnSelect = document.getElementById('target_column'); | |
| if (targetColumnSelect) { | |
| targetColumnSelect.addEventListener('change', function() { | |
| console.log('Target column selected:', this.value); | |
| // You can add more logic here if needed | |
| }); | |
| } | |
| // Problem type auto-suggestion (placeholder for future enhancement) | |
| const problemTypeSelect = document.getElementById('problem_type'); | |
| if (problemTypeSelect && targetColumnSelect) { | |
| targetColumnSelect.addEventListener('change', function() { | |
| // This would need backend integration to suggest problem type | |
| // based on target column data type | |
| }); | |
| } | |
| // Rating selection animation | |
| const ratingInputs = document.querySelectorAll('input[name="rating"]'); | |
| ratingInputs.forEach(input => { | |
| input.addEventListener('change', function() { | |
| const label = document.querySelector(`label[for="${this.id}"]`); | |
| if (label) { | |
| label.style.transform = 'scale(1.1)'; | |
| setTimeout(() => { | |
| label.style.transform = 'scale(1)'; | |
| }, 200); | |
| } | |
| }); | |
| }); | |
| // Copy code functionality for documentation | |
| const codeBlocks = document.querySelectorAll('pre code'); | |
| codeBlocks.forEach(block => { | |
| const copyBtn = document.createElement('button'); | |
| copyBtn.className = 'btn btn-sm btn-outline-secondary position-absolute top-0 end-0 m-2'; | |
| copyBtn.innerHTML = '<i class="fas fa-copy"></i>'; | |
| copyBtn.title = 'Copy code'; | |
| const pre = block.parentElement; | |
| pre.style.position = 'relative'; | |
| pre.appendChild(copyBtn); | |
| copyBtn.addEventListener('click', function() { | |
| navigator.clipboard.writeText(block.textContent).then(() => { | |
| copyBtn.innerHTML = '<i class="fas fa-check"></i>'; | |
| setTimeout(() => { | |
| copyBtn.innerHTML = '<i class="fas fa-copy"></i>'; | |
| }, 2000); | |
| }); | |
| }); | |
| }); | |
| // Prediction table enhancement | |
| const predictionTable = document.querySelector('table'); | |
| if (predictionTable && window.location.pathname.includes('/predict')) { | |
| // Add search functionality | |
| const searchInput = document.createElement('input'); | |
| searchInput.type = 'text'; | |
| searchInput.className = 'form-control mb-3'; | |
| searchInput.placeholder = 'Search predictions...'; | |
| predictionTable.parentElement.insertBefore(searchInput, predictionTable); | |
| searchInput.addEventListener('input', function() { | |
| const searchTerm = this.value.toLowerCase(); | |
| const rows = predictionTable.querySelectorAll('tbody tr'); | |
| rows.forEach(row => { | |
| const text = row.textContent.toLowerCase(); | |
| row.style.display = text.includes(searchTerm) ? '' : 'none'; | |
| }); | |
| }); | |
| } | |
| // Add confirmation dialog for important actions | |
| const dangerButtons = document.querySelectorAll('.btn-danger'); | |
| dangerButtons.forEach(btn => { | |
| if (btn.textContent.toLowerCase().includes('delete') || | |
| btn.textContent.toLowerCase().includes('remove')) { | |
| btn.addEventListener('click', function(e) { | |
| if (!confirm('Are you sure you want to proceed?')) { | |
| e.preventDefault(); | |
| } | |
| }); | |
| } | |
| }); | |
| // Performance monitoring | |
| if (window.performance) { | |
| window.addEventListener('load', function() { | |
| const loadTime = window.performance.timing.loadEventEnd - | |
| window.performance.timing.navigationStart; | |
| console.log('Page load time:', (loadTime / 1000).toFixed(2), 'seconds'); | |
| }); | |
| } | |
| // Add active class to current nav item | |
| const currentLocation = window.location.pathname; | |
| const navLinks = document.querySelectorAll('.nav-link'); | |
| navLinks.forEach(link => { | |
| if (link.getAttribute('href') === currentLocation) { | |
| link.classList.add('active'); | |
| } | |
| }); | |
| // File size formatter | |
| window.formatFileSize = function(bytes) { | |
| if (bytes === 0) return '0 Bytes'; | |
| const k = 1024; | |
| const sizes = ['Bytes', 'KB', 'MB', 'GB']; | |
| const i = Math.floor(Math.log(bytes) / Math.log(k)); | |
| return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i]; | |
| }; | |
| // Number formatter | |
| window.formatNumber = function(num, decimals = 2) { | |
| return parseFloat(num).toFixed(decimals); | |
| }; | |
| console.log('Data2Model initialized successfully!'); | |
| }); | |
| // Export utility functions | |
| window.Data2Model = { | |
| showLoading: function(element, text = 'Loading...') { | |
| element.innerHTML = `<span class="loading"></span> ${text}`; | |
| element.disabled = true; | |
| }, | |
| hideLoading: function(element, text) { | |
| element.innerHTML = text; | |
| element.disabled = false; | |
| }, | |
| showAlert: function(message, type = 'info') { | |
| const alertDiv = document.createElement('div'); | |
| alertDiv.className = `alert alert-${type} alert-dismissible fade show`; | |
| alertDiv.innerHTML = ` | |
| ${message} | |
| <button type="button" class="btn-close" data-bs-dismiss="alert"></button> | |
| `; | |
| const container = document.querySelector('.container'); | |
| if (container) { | |
| container.insertBefore(alertDiv, container.firstChild); | |
| setTimeout(() => { | |
| const bsAlert = new bootstrap.Alert(alertDiv); | |
| bsAlert.close(); | |
| }, 5000); | |
| } | |
| } | |
| }; | |