Add component: GPU Monitor
#15
by
elismasilva - opened
- components/gpu-monitor.json +23 -0
- manifest.json +13 -0
components/gpu-monitor.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": "gpu-monitor",
|
| 3 |
+
"name": "GPU Monitor",
|
| 4 |
+
"description": "A real-time GPU monitoring component for Gradio apps Inspired by the GPU monitoring widget from the Ostris AI-Toolkit. Perfect for AI training dashboards, LLM hosting interfaces, or any Gradio app where users need to keep an eye on hardware resource consumption.",
|
| 5 |
+
"author": "elismasilva",
|
| 6 |
+
"tags": [
|
| 7 |
+
"monitoring",
|
| 8 |
+
"gpu",
|
| 9 |
+
"training",
|
| 10 |
+
"dashboard"
|
| 11 |
+
],
|
| 12 |
+
"html_template": "\n <div class=\"gpu-monitor-container\">\n <div class=\"gpu-header\">\n <h1 class=\"gpu-title\">GPU Monitor</h1>\n ${show_last_updated === 'true' ? `<div class=\"gpu-time\">Last updated: <span id=\"gpu-time-val\">Loading...</span></div>` : ''}\n </div>\n <div id=\"gpu-alert\"></div>\n <div id=\"gpu-root\" class=\"gpu-grid\"></div>\n </div>\n ",
|
| 13 |
+
"css_template": "\n .gpu-monitor-container {\n font-family: \"Inter\", sans-serif;\n width: 100%;\n }\n\n .gpu-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 1rem;\n }\n\n .gpu-title {\n font-size: 1.125rem;\n margin: 0;\n font-weight: 500;\n color: var(--body-text-color);\n }\n\n .gpu-time {\n font-size: 0.75rem;\n color: var(--body-text-color-subdued);\n }\n\n .gpu-grid {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));\n gap: 1rem;\n }\n\n .gpu-card {\n background-color: var(--background-fill-secondary);\n border-radius: 0.75rem;\n box-shadow: var(--shadow-drop-md);\n border: 1px solid var(--border-color-primary);\n overflow: hidden;\n transition: box-shadow 0.3s ease;\n }\n\n .gpu-card:hover {\n box-shadow: var(--shadow-drop-lg);\n }\n\n .gpu-card-header {\n background-color: var(--background-fill-primary);\n padding: 0.75rem 1rem;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-bottom: 1px solid var(--border-color-primary);\n }\n\n .gpu-name {\n font-weight: 600;\n color: var(--body-text-color);\n margin: 0;\n font-size: 0.9rem;\n }\n\n .gpu-badge {\n padding: 0.125rem 0.5rem;\n background-color: var(--background-fill-secondary);\n border-radius: 9999px;\n font-size: 0.75rem;\n color: var(--body-text-color);\n }\n\n .gpu-body {\n padding: 1rem;\n }\n\n .gpu-metrics-grid {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 1rem;\n }\n\n .metric-item {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n margin-bottom: 0.75rem;\n }\n\n .metric-label {\n font-size: 0.75rem;\n color: var(--body-text-color-subdued);\n margin: 0;\n }\n\n .metric-value {\n font-size: 0.875rem;\n font-weight: 500;\n margin: 0;\n color: var(--body-text-color);\n }\n\n .progress-header {\n display: flex;\n align-items: center;\n margin-bottom: 0.25rem;\n }\n\n .progress-header span {\n margin-left: auto;\n font-size: 0.75rem;\n color: var(--body-text-color);\n }\n\n .progress-track {\n width: 100%;\n background-color: var(--neutral-200);\n border-radius: 9999px;\n height: 0.35rem;\n margin-bottom: 0.75rem;\n overflow: hidden;\n }\n\n .progress-fill {\n height: 100%;\n border-radius: 9999px;\n transition:\n width 0.3s ease,\n background-color 0.3s ease;\n }\n\n .progress-footer {\n font-size: 0.75rem;\n color: var(--body-text-color-subdued);\n margin-top: -0.5rem;\n }\n\n .gpu-footer {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 1rem;\n padding-top: 0.5rem;\n margin-top: 0.5rem;\n border-top: 1px solid var(--border-color-primary);\n }\n\n .text-emerald-500 {\n color: #10b981 !important;\n stroke: #10b981 !important;\n }\n\n .bg-emerald-500 {\n background-color: #10b981 !important;\n }\n\n .text-amber-500 {\n color: #f59e0b !important;\n stroke: #f59e0b !important;\n }\n\n .bg-amber-500 {\n background-color: #f59e0b !important;\n }\n\n .text-rose-500 {\n color: #f43f5e !important;\n stroke: #f43f5e !important;\n }\n\n .bg-rose-500 {\n background-color: #f43f5e !important;\n }\n\n .text-blue-500 {\n color: #3b82f6 !important;\n stroke: #3b82f6 !important;\n }\n\n .bg-blue-500 {\n background-color: #3b82f6 !important;\n }\n\n .text-purple-500 {\n color: #a855f7 !important;\n stroke: #a855f7 !important;\n }\n\n .icon-muted {\n color: var(--body-text-color-subdued) !important;\n stroke: var(--body-text-color-subdued) !important;\n }\n\n .icon {\n width: 16px;\n height: 16px;\n stroke-width: 2.2;\n }\n\n .alert-box {\n background-color: rgba(245, 158, 11, 0.1);\n border: 1px solid #f59e0b;\n color: #d97706;\n padding: 0.75rem 1rem;\n border-radius: 0.5rem;\n margin-bottom: 1rem;\n font-size: 0.875rem;\n }\n ",
|
| 14 |
+
"js_on_load": "\n const root = element.querySelector('#gpu-root');\n const timeVal = element.querySelector('#gpu-time-val');\n const alertBox = element.querySelector('#gpu-alert');\n let intervalId;\n let renderedGpuCount = -1; \n\n const formatMemory = (mb) => mb >= 1024 ? `${(mb / 1024).toFixed(1)} GB` : `${mb} MB`;\n const getUtilColor = (val) => val < 30 ? 'bg-emerald-500' : val < 70 ? 'bg-amber-500' : 'bg-rose-500';\n const getTempColor = (temp) => temp < 50 ? 'text-emerald-500' : temp < 80 ? 'text-amber-500' : 'text-rose-500';\n\n function initLucide(retries = 8, delay = 200) {\n if (window.lucide) {\n window.lucide.createIcons({ root: root });\n } else if (retries > 0) {\n setTimeout(() => initLucide(retries - 1, delay), delay);\n }\n }\n\n const generateGPUCard = (gpu) => `\n <div class=\"gpu-card\" id=\"gpu-card-${gpu.index}\">\n <div class=\"gpu-card-header\">\n <h2 class=\"gpu-name\">${gpu.name}</h2>\n <span class=\"gpu-badge\"># ${gpu.index}</span>\n </div>\n <div class=\"gpu-body\">\n <div class=\"gpu-metrics-grid\">\n <div>\n <div class=\"metric-item\">\n <i data-lucide=\"thermometer\" id=\"icon-temp-${gpu.index}\" class=\"icon ${getTempColor(gpu.temperature)}\"></i>\n <div>\n <p class=\"metric-label\">Temperature</p>\n <p class=\"metric-value ${getTempColor(gpu.temperature)}\" id=\"val-temp-${gpu.index}\">${gpu.temperature}\u00b0C</p>\n </div>\n </div>\n <div class=\"metric-item\">\n <i data-lucide=\"fan\" class=\"icon text-blue-500\"></i>\n <div>\n <p class=\"metric-label\">Fan Speed</p>\n <p class=\"metric-value text-blue-500\" id=\"val-fan-${gpu.index}\">${gpu.fan.speed}%</p>\n </div>\n </div>\n </div>\n <div>\n <div class=\"progress-header\">\n <i data-lucide=\"cpu\" class=\"icon icon-muted\" style=\"margin-right:4px;\"></i>\n <p class=\"metric-label\">GPU Load</p>\n <span id=\"val-util-${gpu.index}\">${gpu.utilization.gpu}%</span>\n </div>\n <div class=\"progress-track\">\n <div id=\"bar-util-${gpu.index}\" class=\"progress-fill ${getUtilColor(gpu.utilization.gpu)}\" style=\"width: ${gpu.utilization.gpu}%\"></div>\n </div>\n \n <div class=\"progress-header\" style=\"margin-top: 12px;\">\n <i data-lucide=\"hard-drive\" class=\"icon text-blue-500\" style=\"margin-right:4px;\"></i>\n <p class=\"metric-label\">Memory</p>\n <span id=\"val-mem-pct-${gpu.index}\">${((gpu.memory.used / gpu.memory.total) * 100).toFixed(1)}%</span>\n </div>\n <div class=\"progress-track\">\n <div id=\"bar-mem-${gpu.index}\" class=\"progress-fill bg-blue-500\" style=\"width: ${(gpu.memory.used / gpu.memory.total) * 100}%\"></div>\n </div>\n <p class=\"progress-footer\" id=\"val-mem-text-${gpu.index}\">${formatMemory(gpu.memory.used)} / ${formatMemory(gpu.memory.total)}</p>\n </div>\n </div>\n <div class=\"gpu-footer\">\n <div class=\"metric-item\" style=\"margin:0\">\n <i data-lucide=\"clock\" class=\"icon text-purple-500\"></i>\n <div>\n <p class=\"metric-label\">Clock Speed</p>\n <p class=\"metric-value\" id=\"val-clock-${gpu.index}\">${gpu.clocks.graphics} MHz</p>\n </div>\n </div>\n <div class=\"metric-item\" style=\"margin:0\">\n <i data-lucide=\"zap\" class=\"icon text-amber-500\"></i>\n <div>\n <p class=\"metric-label\">Power Draw</p>\n <p class=\"metric-value\"><span id=\"val-power-${gpu.index}\">${gpu.power.draw.toFixed(1)}</span>W <span style=\"font-size:0.7rem; color:var(--body-text-color-subdued)\">/ ${gpu.power.limit}W</span></p>\n </div>\n </div>\n </div>\n </div>\n </div>\n `;\n\n function updateGpuDOM(gpus) {\n gpus.forEach(gpu => {\n document.getElementById(`val-temp-${gpu.index}`).innerText = `${gpu.temperature}\u00b0C`;\n document.getElementById(`val-fan-${gpu.index}`).innerText = `${gpu.fan.speed}%`;\n document.getElementById(`val-util-${gpu.index}`).innerText = `${gpu.utilization.gpu}%`;\n document.getElementById(`val-mem-pct-${gpu.index}`).innerText = `${((gpu.memory.used / gpu.memory.total) * 100).toFixed(1)}%`;\n document.getElementById(`val-mem-text-${gpu.index}`).innerText = `${formatMemory(gpu.memory.used)} / ${formatMemory(gpu.memory.total)}`;\n document.getElementById(`val-clock-${gpu.index}`).innerText = `${gpu.clocks.graphics} MHz`;\n document.getElementById(`val-power-${gpu.index}`).innerText = `${gpu.power.draw.toFixed(1)}`;\n \n const utilBar = document.getElementById(`bar-util-${gpu.index}`);\n utilBar.style.width = `${gpu.utilization.gpu}%`;\n utilBar.className = `progress-fill ${getUtilColor(gpu.utilization.gpu)}`;\n \n document.getElementById(`bar-mem-${gpu.index}`).style.width = `${(gpu.memory.used / gpu.memory.total) * 100}%`;\n \n const newTempClass = getTempColor(gpu.temperature);\n document.getElementById(`val-temp-${gpu.index}`).className = `metric-value ${newTempClass}`;\n \n const tempIconSvg = document.getElementById(`icon-temp-${gpu.index}`);\n if(tempIconSvg) {\n tempIconSvg.setAttribute('class', `lucide lucide-thermometer icon ${newTempClass}`);\n }\n });\n }\n\n async function fetchAndUpdate() {\n try {\n const data = await server.get_gpu_stats();\n \n if (timeVal) {\n timeVal.innerText = new Date().toLocaleTimeString();\n }\n\n if (!data.hasNvidiaSmi && data.error) {\n alertBox.innerHTML = `<div class=\"alert-box\"><strong>Nota:</strong> ${data.error}</div>`;\n }\n\n if (data.gpus && data.gpus.length > 0) {\n if (data.gpus.length !== renderedGpuCount) {\n root.innerHTML = data.gpus.map(gpu => generateGPUCard(gpu)).join('');\n initLucide();\n renderedGpuCount = data.gpus.length;\n } else {\n updateGpuDOM(data.gpus);\n }\n } else {\n root.innerHTML = '<div style=\"color:var(--body-text-color)\">No GPUs found.</div>';\n }\n } catch (error) {\n console.error(\"Fetch GPU error:\", error);\n }\n }\n\n fetchAndUpdate(); \n intervalId = setInterval(fetchAndUpdate, props.update_interval);\n return () => clearInterval(intervalId);\n ",
|
| 15 |
+
"default_props": {
|
| 16 |
+
"value": "",
|
| 17 |
+
"update_interval": 2000,
|
| 18 |
+
"show_last_updated": "true"
|
| 19 |
+
},
|
| 20 |
+
"python_code": "class GPUMonitor(gr.HTML):\n def __init__(\n self, \n update_interval=1000,\n show_last_updated=True,\n **kwargs\n ):\n\n html_template = \"\"\"\n <div class=\"gpu-monitor-container\">\n <div class=\"gpu-header\">\n <h1 class=\"gpu-title\">GPU Monitor</h1>\n ${show_last_updated === 'true' ? `<div class=\"gpu-time\">Last updated: <span id=\"gpu-time-val\">Loading...</span></div>` : ''}\n </div>\n <div id=\"gpu-alert\"></div>\n <div id=\"gpu-root\" class=\"gpu-grid\"></div>\n </div>\n \"\"\"\n\n css_template = \"\"\"\n .gpu-monitor-container {\n font-family: \"Inter\", sans-serif;\n width: 100%;\n }\n\n .gpu-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 1rem;\n }\n\n .gpu-title {\n font-size: 1.125rem;\n margin: 0;\n font-weight: 500;\n color: var(--body-text-color);\n }\n\n .gpu-time {\n font-size: 0.75rem;\n color: var(--body-text-color-subdued);\n }\n\n .gpu-grid {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));\n gap: 1rem;\n }\n\n .gpu-card {\n background-color: var(--background-fill-secondary);\n border-radius: 0.75rem;\n box-shadow: var(--shadow-drop-md);\n border: 1px solid var(--border-color-primary);\n overflow: hidden;\n transition: box-shadow 0.3s ease;\n }\n\n .gpu-card:hover {\n box-shadow: var(--shadow-drop-lg);\n }\n\n .gpu-card-header {\n background-color: var(--background-fill-primary);\n padding: 0.75rem 1rem;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-bottom: 1px solid var(--border-color-primary);\n }\n\n .gpu-name {\n font-weight: 600;\n color: var(--body-text-color);\n margin: 0;\n font-size: 0.9rem;\n }\n\n .gpu-badge {\n padding: 0.125rem 0.5rem;\n background-color: var(--background-fill-secondary);\n border-radius: 9999px;\n font-size: 0.75rem;\n color: var(--body-text-color);\n }\n\n .gpu-body {\n padding: 1rem;\n }\n\n .gpu-metrics-grid {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 1rem;\n }\n\n .metric-item {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n margin-bottom: 0.75rem;\n }\n\n .metric-label {\n font-size: 0.75rem;\n color: var(--body-text-color-subdued);\n margin: 0;\n }\n\n .metric-value {\n font-size: 0.875rem;\n font-weight: 500;\n margin: 0;\n color: var(--body-text-color);\n }\n\n .progress-header {\n display: flex;\n align-items: center;\n margin-bottom: 0.25rem;\n }\n\n .progress-header span {\n margin-left: auto;\n font-size: 0.75rem;\n color: var(--body-text-color);\n }\n\n .progress-track {\n width: 100%;\n background-color: var(--neutral-200);\n border-radius: 9999px;\n height: 0.35rem;\n margin-bottom: 0.75rem;\n overflow: hidden;\n }\n\n .progress-fill {\n height: 100%;\n border-radius: 9999px;\n transition:\n width 0.3s ease,\n background-color 0.3s ease;\n }\n\n .progress-footer {\n font-size: 0.75rem;\n color: var(--body-text-color-subdued);\n margin-top: -0.5rem;\n }\n\n .gpu-footer {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 1rem;\n padding-top: 0.5rem;\n margin-top: 0.5rem;\n border-top: 1px solid var(--border-color-primary);\n }\n\n .text-emerald-500 {\n color: #10b981 !important;\n stroke: #10b981 !important;\n }\n\n .bg-emerald-500 {\n background-color: #10b981 !important;\n }\n\n .text-amber-500 {\n color: #f59e0b !important;\n stroke: #f59e0b !important;\n }\n\n .bg-amber-500 {\n background-color: #f59e0b !important;\n }\n\n .text-rose-500 {\n color: #f43f5e !important;\n stroke: #f43f5e !important;\n }\n\n .bg-rose-500 {\n background-color: #f43f5e !important;\n }\n\n .text-blue-500 {\n color: #3b82f6 !important;\n stroke: #3b82f6 !important;\n }\n\n .bg-blue-500 {\n background-color: #3b82f6 !important;\n }\n\n .text-purple-500 {\n color: #a855f7 !important;\n stroke: #a855f7 !important;\n }\n\n .icon-muted {\n color: var(--body-text-color-subdued) !important;\n stroke: var(--body-text-color-subdued) !important;\n }\n\n .icon {\n width: 16px;\n height: 16px;\n stroke-width: 2.2;\n }\n\n .alert-box {\n background-color: rgba(245, 158, 11, 0.1);\n border: 1px solid #f59e0b;\n color: #d97706;\n padding: 0.75rem 1rem;\n border-radius: 0.5rem;\n margin-bottom: 1rem;\n font-size: 0.875rem;\n }\n \"\"\"\n\n js_on_load = \"\"\"\n const root = element.querySelector('#gpu-root');\n const timeVal = element.querySelector('#gpu-time-val');\n const alertBox = element.querySelector('#gpu-alert');\n let intervalId;\n let renderedGpuCount = -1; \n\n const formatMemory = (mb) => mb >= 1024 ? `${(mb / 1024).toFixed(1)} GB` : `${mb} MB`;\n const getUtilColor = (val) => val < 30 ? 'bg-emerald-500' : val < 70 ? 'bg-amber-500' : 'bg-rose-500';\n const getTempColor = (temp) => temp < 50 ? 'text-emerald-500' : temp < 80 ? 'text-amber-500' : 'text-rose-500';\n\n function initLucide(retries = 8, delay = 200) {\n if (window.lucide) {\n window.lucide.createIcons({ root: root });\n } else if (retries > 0) {\n setTimeout(() => initLucide(retries - 1, delay), delay);\n }\n }\n\n const generateGPUCard = (gpu) => `\n <div class=\"gpu-card\" id=\"gpu-card-${gpu.index}\">\n <div class=\"gpu-card-header\">\n <h2 class=\"gpu-name\">${gpu.name}</h2>\n <span class=\"gpu-badge\"># ${gpu.index}</span>\n </div>\n <div class=\"gpu-body\">\n <div class=\"gpu-metrics-grid\">\n <div>\n <div class=\"metric-item\">\n <i data-lucide=\"thermometer\" id=\"icon-temp-${gpu.index}\" class=\"icon ${getTempColor(gpu.temperature)}\"></i>\n <div>\n <p class=\"metric-label\">Temperature</p>\n <p class=\"metric-value ${getTempColor(gpu.temperature)}\" id=\"val-temp-${gpu.index}\">${gpu.temperature}\u00b0C</p>\n </div>\n </div>\n <div class=\"metric-item\">\n <i data-lucide=\"fan\" class=\"icon text-blue-500\"></i>\n <div>\n <p class=\"metric-label\">Fan Speed</p>\n <p class=\"metric-value text-blue-500\" id=\"val-fan-${gpu.index}\">${gpu.fan.speed}%</p>\n </div>\n </div>\n </div>\n <div>\n <div class=\"progress-header\">\n <i data-lucide=\"cpu\" class=\"icon icon-muted\" style=\"margin-right:4px;\"></i>\n <p class=\"metric-label\">GPU Load</p>\n <span id=\"val-util-${gpu.index}\">${gpu.utilization.gpu}%</span>\n </div>\n <div class=\"progress-track\">\n <div id=\"bar-util-${gpu.index}\" class=\"progress-fill ${getUtilColor(gpu.utilization.gpu)}\" style=\"width: ${gpu.utilization.gpu}%\"></div>\n </div>\n\n <div class=\"progress-header\" style=\"margin-top: 12px;\">\n <i data-lucide=\"hard-drive\" class=\"icon text-blue-500\" style=\"margin-right:4px;\"></i>\n <p class=\"metric-label\">Memory</p>\n <span id=\"val-mem-pct-${gpu.index}\">${((gpu.memory.used / gpu.memory.total) * 100).toFixed(1)}%</span>\n </div>\n <div class=\"progress-track\">\n <div id=\"bar-mem-${gpu.index}\" class=\"progress-fill bg-blue-500\" style=\"width: ${(gpu.memory.used / gpu.memory.total) * 100}%\"></div>\n </div>\n <p class=\"progress-footer\" id=\"val-mem-text-${gpu.index}\">${formatMemory(gpu.memory.used)} / ${formatMemory(gpu.memory.total)}</p>\n </div>\n </div>\n <div class=\"gpu-footer\">\n <div class=\"metric-item\" style=\"margin:0\">\n <i data-lucide=\"clock\" class=\"icon text-purple-500\"></i>\n <div>\n <p class=\"metric-label\">Clock Speed</p>\n <p class=\"metric-value\" id=\"val-clock-${gpu.index}\">${gpu.clocks.graphics} MHz</p>\n </div>\n </div>\n <div class=\"metric-item\" style=\"margin:0\">\n <i data-lucide=\"zap\" class=\"icon text-amber-500\"></i>\n <div>\n <p class=\"metric-label\">Power Draw</p>\n <p class=\"metric-value\"><span id=\"val-power-${gpu.index}\">${gpu.power.draw.toFixed(1)}</span>W <span style=\"font-size:0.7rem; color:var(--body-text-color-subdued)\">/ ${gpu.power.limit}W</span></p>\n </div>\n </div>\n </div>\n </div>\n </div>\n `;\n\n function updateGpuDOM(gpus) {\n gpus.forEach(gpu => {\n document.getElementById(`val-temp-${gpu.index}`).innerText = `${gpu.temperature}\u00b0C`;\n document.getElementById(`val-fan-${gpu.index}`).innerText = `${gpu.fan.speed}%`;\n document.getElementById(`val-util-${gpu.index}`).innerText = `${gpu.utilization.gpu}%`;\n document.getElementById(`val-mem-pct-${gpu.index}`).innerText = `${((gpu.memory.used / gpu.memory.total) * 100).toFixed(1)}%`;\n document.getElementById(`val-mem-text-${gpu.index}`).innerText = `${formatMemory(gpu.memory.used)} / ${formatMemory(gpu.memory.total)}`;\n document.getElementById(`val-clock-${gpu.index}`).innerText = `${gpu.clocks.graphics} MHz`;\n document.getElementById(`val-power-${gpu.index}`).innerText = `${gpu.power.draw.toFixed(1)}`;\n\n const utilBar = document.getElementById(`bar-util-${gpu.index}`);\n utilBar.style.width = `${gpu.utilization.gpu}%`;\n utilBar.className = `progress-fill ${getUtilColor(gpu.utilization.gpu)}`;\n\n document.getElementById(`bar-mem-${gpu.index}`).style.width = `${(gpu.memory.used / gpu.memory.total) * 100}%`;\n\n const newTempClass = getTempColor(gpu.temperature);\n document.getElementById(`val-temp-${gpu.index}`).className = `metric-value ${newTempClass}`;\n\n const tempIconSvg = document.getElementById(`icon-temp-${gpu.index}`);\n if(tempIconSvg) {\n tempIconSvg.setAttribute('class', `lucide lucide-thermometer icon ${newTempClass}`);\n }\n });\n }\n\n async function fetchAndUpdate() {\n try {\n const data = await server.get_gpu_stats();\n\n if (timeVal) {\n timeVal.innerText = new Date().toLocaleTimeString();\n }\n\n if (!data.hasNvidiaSmi && data.error) {\n alertBox.innerHTML = `<div class=\"alert-box\"><strong>Nota:</strong> ${data.error}</div>`;\n }\n\n if (data.gpus && data.gpus.length > 0) {\n if (data.gpus.length !== renderedGpuCount) {\n root.innerHTML = data.gpus.map(gpu => generateGPUCard(gpu)).join('');\n initLucide();\n renderedGpuCount = data.gpus.length;\n } else {\n updateGpuDOM(data.gpus);\n }\n } else {\n root.innerHTML = '<div style=\"color:var(--body-text-color)\">No GPUs found.</div>';\n }\n } catch (error) {\n console.error(\"Fetch GPU error:\", error);\n }\n }\n\n fetchAndUpdate(); \n intervalId = setInterval(fetchAndUpdate, props.update_interval);\n return () => clearInterval(intervalId);\n \"\"\"\n\n super().__init__(\n html_template=html_template, \n css_template=css_template, \n js_on_load=js_on_load, \n server_functions=[get_gpu_stats],\n update_interval=update_interval,\n show_last_updated=str(show_last_updated).lower(),\n **kwargs\n )\n\n def api_info(self): return {\"type\": \"null\"}\n",
|
| 21 |
+
"head": "<script src=\"https://unpkg.com/lucide@latest\"></script>",
|
| 22 |
+
"repo_url": "https://huggingface.co/spaces/elismasilva/gradio_gpu_monitor"
|
| 23 |
+
}
|
manifest.json
CHANGED
|
@@ -203,5 +203,18 @@
|
|
| 203 |
"segmentation"
|
| 204 |
],
|
| 205 |
"repo_url": "https://github.com/hysts/gradio-trimap-editor"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
}
|
| 207 |
]
|
|
|
|
| 203 |
"segmentation"
|
| 204 |
],
|
| 205 |
"repo_url": "https://github.com/hysts/gradio-trimap-editor"
|
| 206 |
+
},
|
| 207 |
+
{
|
| 208 |
+
"id": "gpu-monitor",
|
| 209 |
+
"name": "GPU Monitor",
|
| 210 |
+
"description": "A real-time GPU monitoring component for Gradio apps Inspired by the GPU monitoring widget from the Ostris AI-Toolkit. Perfect for AI training dashboards, LLM hosting interfaces, or any Gradio app where users need to keep an eye on hardware resource consumption.",
|
| 211 |
+
"author": "elismasilva",
|
| 212 |
+
"tags": [
|
| 213 |
+
"monitoring",
|
| 214 |
+
"gpu",
|
| 215 |
+
"training",
|
| 216 |
+
"dashboard"
|
| 217 |
+
],
|
| 218 |
+
"repo_url": "https://huggingface.co/spaces/elismasilva/gradio_gpu_monitor"
|
| 219 |
}
|
| 220 |
]
|