corrected memory issue
Browse files42 unmodified lines4344454647484950515253545556575842 unmodified linesST_DIALOG = getattr(st, "dialog", None) or getattr(st, "experimental_dialog", None)def render_system_status():"""Render a small live CPU/memory status panel in the sidebar."""if not HAS_PSUTIL:returntry:cpu = psutil.cpu_percent(interval=0.1)mem = psutil.virtual_memory()mem_used_gb = mem.used / (1024**3)mem_total_gb = mem.total / (1024**3)mem_pct = mem.percentst.sidebar.markdown(f"""<div style="42 unmodified lines43444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110242 unmodified linesST_DIALOG = getattr(st, "dialog", None) or getattr(st, "experimental_dialog", None)def _get_container_memory():"""Read memory from cgroups when running in a container (Docker, HF Spaces).psutil reports host memory in containers, which can be misleading (e.g. 128 GB vs 16 GB limit).Returns (used_bytes, total_bytes) or None to fall back to psutil."""try:# cgroup v2 (modern Docker, HF Spaces)for base in ("/sys/fs/cgroup", "/sys/fs/cgroup/self"):try:with open(f"{base}/memory.max", "r") as f:max_val = f.read().strip()if max_val == "max":return None # No limit, use psutiltotal = int(max_val)with open(f"{base}/memory.current", "r") as f:used = int(f.read().strip())return (used, total)except (FileNotFoundError, ValueError):continue# cgroup v1try:with open("/sys/fs/cgroup/memory/memory.limit_in_bytes", "r") as f:total = int(f.read().strip())with open("/sys/fs/cgroup/memory/memory.usage_in_bytes", "r") as f:used = int(f.read().strip())if total > 2**50: # Often 9223372036854771712 when unlimitedreturn Nonereturn (used, total)except (FileNotFoundError, ValueError):passexcept Exception:passreturn Nonedef render_system_status():"""Render a small live CPU/memory status panel in the sidebar."""if not HAS_PSUTIL:returntry:cpu = psutil.cpu_percent(interval=0.1)# Prefer cgroup memory in containers (Docker, HF Spaces); psutil shows host memorycontainer_mem = _get_container_memory()if container_mem is not None:used_bytes, total_bytes = container_memmem_used_gb = used_bytes / (1024**3)mem_total_gb = total_bytes / (1024**3)mem_pct = 100 * used_bytes / total_bytes if total_bytes > 0 else 0else:mem = psutil.virtual_memory()mem_used_gb = mem.used / (1024**3)mem_total_gb = mem.total / (1024**3)mem_pct = mem.percentst.sidebar.markdown(f"""<div style="
S2FApp/ui/components.py+48-4