File size: 1,747 Bytes
e4d73f9 | 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 | # utils/hardware.py
"""
Cached hardware detection for the ECG Dashboard sidebar.
Uses @st.cache_data to avoid re-running expensive subprocess/torch calls on every Streamlit rerun.
"""
import platform
import subprocess
import streamlit as st
@st.cache_data(show_spinner=False)
def get_cpu_name() -> str:
"""Detect CPU name. Cached so it only runs once per session."""
try:
return subprocess.check_output(
"wmic cpu get name", shell=True
).decode().split("\n")[1].strip()
except Exception:
return platform.processor().split(',')[0].strip()
@st.cache_data(show_spinner=False)
def get_gpu_info() -> dict:
"""
Detect GPU availability and details.
Cached so the heavy `import torch` only happens once per session.
Returns dict with keys: available, name, vram_gb.
"""
try:
import torch
if torch.cuda.is_available():
return {
"available": True,
"name": torch.cuda.get_device_name(0),
"vram_gb": torch.cuda.get_device_properties(0).total_memory / 1e9
}
except ImportError:
pass
return {"available": False, "name": None, "vram_gb": None}
def render_sidebar_hardware():
"""Render the hardware info panel in the sidebar using cached data."""
st.sidebar.markdown("### ๐ Clinical Workstation Info")
cpu = get_cpu_name()
st.sidebar.markdown(f"**๐ฅ๏ธ CPU:**\n`{cpu}`")
gpu = get_gpu_info()
if gpu["available"]:
st.sidebar.markdown(
f"**๐ GPU:**\n`{gpu['name']}`\n"
f"`CUDA Active | VRAM: {gpu['vram_gb']:.1f} GB`"
)
else:
st.sidebar.markdown("**๐ GPU:**\n`Not Detected (Running on CPU)`")
|