let nvmlInterval = null; // eslint-disable-line prefer-const let nvmlEl = null; let nvmlTable = null; async function updateNVML() { try { const res = await fetch('/sdapi/v1/nvml'); if (!res.ok) { clearInterval(nvmlInterval); nvmlEl.style.display = 'none'; return; } const data = await res.json(); if (!data) { clearInterval(nvmlInterval); nvmlEl.style.display = 'none'; return; } const nvmlTbody = nvmlTable.querySelector('tbody'); for (const gpu of data) { const rows = ` GPU${gpu.name} Driver${gpu.version.driver} VBIOS${gpu.version.vbios} ROM${gpu.version.rom} Driver${gpu.version.driver} PCIGen.${gpu.pci.link} x${gpu.pci.width} Memory${gpu.memory.used}Mb / ${gpu.memory.total}Mb Clock${gpu.clock.gpu[0]}Mhz / ${gpu.clock.gpu[1]}Mhz Power${gpu.power[0]}W / ${gpu.power[1]}W Load GPU${gpu.load.gpu}% Load Memory${gpu.load.memory}% Temperature${gpu.load.temp}°C Fans${gpu.load.fan}% State${gpu.state} `; nvmlTbody.innerHTML = rows; } nvmlEl.style.display = 'block'; } catch (e) { clearInterval(nvmlInterval); nvmlEl.style.display = 'none'; } } async function initNVML() { nvmlEl = document.getElementById('nvml'); if (!nvmlEl) { nvmlEl = document.createElement('div'); nvmlEl.className = 'nvml'; nvmlEl.id = 'nvml'; nvmlTable = document.createElement('table'); nvmlTable.className = 'nvml-table'; nvmlTable.id = 'nvml-table'; nvmlTable.innerHTML = ` `; nvmlEl.appendChild(nvmlTable); gradioApp().appendChild(nvmlEl); log('initNVML'); } if (nvmlInterval) { clearInterval(nvmlInterval); nvmlInterval = null; nvmlEl.style.display = 'none'; } else { nvmlInterval = setInterval(updateNVML, 1000); } } async function disableNVML() { clearInterval(nvmlInterval); nvmlEl.style.display = 'none'; }