From c3a0b2b09e0e6db44ecbb3cf291b95df67448d5b Mon Sep 17 00:00:00 2001 From: Soubhagya Mohapatra Date: Wed, 12 Mar 2025 20:56:16 +0530 Subject: [PATCH 1/4] Add CPU visualizer --- requirements.txt | 1 + src/common/common.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 471436f25..95615786e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ plotly==5.22.0 captcha==0.5.0 pyopenms_viz==1.0.0 streamlit-js-eval +psutil==7.0.0 \ No newline at end of file diff --git a/src/common/common.py b/src/common/common.py index ca8231307..e09ca9f7f 100644 --- a/src/common/common.py +++ b/src/common/common.py @@ -10,7 +10,7 @@ import streamlit as st import pandas as pd - +import psutil try: from tkinter import Tk, filedialog @@ -23,6 +23,18 @@ # Detect system platform OS_PLATFORM = sys.platform +@st.fragment(run_every=5) +def monitor_hardware(): + cpu_progress = psutil.cpu_percent(interval=None) / 100 + ram_progress = 1 - psutil.virtual_memory().available / psutil.virtual_memory().total + + st.text(f"Ram ({ram_progress * 100:.2f}%)") + st.progress(ram_progress) + + st.write(f"CPU ({cpu_progress * 100:.2f}%)") + st.progress(cpu_progress) + + st.text(f"Last fetched at: {time.strftime('%H:%M:%S')}") def load_params(default: bool = False) -> dict[str, Any]: """ @@ -279,6 +291,9 @@ def render_sidebar(page: str = "") -> None: """ params = load_params() with st.sidebar: + with st.expander("📊 **CPU Visualisation**"): + monitor_hardware() + # The main page has workspace switcher # Display workspace switcher if workspace is enabled in local mode if st.session_state.settings["enable_workspaces"]: @@ -347,7 +362,7 @@ def change_workspace(): "Number of Bins (m/z)", 1, 10000, 50, key="spectrum_num_bins" ) else: - st.session_state["spectrum_num_bins"] = 50 + st.session_state["spectrum_num_bins"] = 50 # Display OpenMS WebApp Template Version from settings.json with st.container(): From 09ce80971fb9ffe06e22c9406c718060eeeab860 Mon Sep 17 00:00:00 2001 From: Soubhagya Mohapatra Date: Wed, 12 Mar 2025 21:05:55 +0530 Subject: [PATCH 2/4] Add cpu vizualizer section --- environment.yml | 1 + src/common/common.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index 24bed7a90..188d5c118 100644 --- a/environment.yml +++ b/environment.yml @@ -15,3 +15,4 @@ dependencies: - captcha==0.5.0 - pyopenms_viz==1.0.0 - streamlit-js-eval + - psutil==7.0.0 \ No newline at end of file diff --git a/src/common/common.py b/src/common/common.py index e09ca9f7f..78d23a8ae 100644 --- a/src/common/common.py +++ b/src/common/common.py @@ -31,10 +31,10 @@ def monitor_hardware(): st.text(f"Ram ({ram_progress * 100:.2f}%)") st.progress(ram_progress) - st.write(f"CPU ({cpu_progress * 100:.2f}%)") + st.text(f"CPU ({cpu_progress * 100:.2f}%)") st.progress(cpu_progress) - st.text(f"Last fetched at: {time.strftime('%H:%M:%S')}") + st.caption(f"Last fetched at: {time.strftime('%H:%M:%S')}") def load_params(default: bool = False) -> dict[str, Any]: """ From 58de157a1d267766176344426384ed269610f6e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20David=20M=C3=BCller?= <57191390+t0mdavid-m@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:49:00 +0100 Subject: [PATCH 3/4] fix typo --- src/common/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/common.py b/src/common/common.py index 78d23a8ae..3f98397a3 100644 --- a/src/common/common.py +++ b/src/common/common.py @@ -223,7 +223,7 @@ def page_setup(page: str = "") -> dict[str, Any]: if st.session_state.settings["workspaces_dir"] and st.session_state.location == "local": workspaces_dir = Path(st.session_state.settings["workspaces_dir"], "workspaces-" + st.session_state.settings["repository-name"]) else: - workspace_dir = '..' + workspaces_dir = '..' # Check if workspace logic is enabled if st.session_state.settings["enable_workspaces"]: From 66f194394784f46cb2122a207bba90e48494c3f3 Mon Sep 17 00:00:00 2001 From: Soubhagya Mohapatra Date: Wed, 12 Mar 2025 21:48:56 +0530 Subject: [PATCH 4/4] move resource utilization section below settings --- src/common/common.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/common.py b/src/common/common.py index 78d23a8ae..fe3af9a20 100644 --- a/src/common/common.py +++ b/src/common/common.py @@ -291,9 +291,6 @@ def render_sidebar(page: str = "") -> None: """ params = load_params() with st.sidebar: - with st.expander("📊 **CPU Visualisation**"): - monitor_hardware() - # The main page has workspace switcher # Display workspace switcher if workspace is enabled in local mode if st.session_state.settings["enable_workspaces"]: @@ -362,7 +359,10 @@ def change_workspace(): "Number of Bins (m/z)", 1, 10000, 50, key="spectrum_num_bins" ) else: - st.session_state["spectrum_num_bins"] = 50 + st.session_state["spectrum_num_bins"] = 50 + + with st.expander("📊 **Resource Utilization**"): + monitor_hardware() # Display OpenMS WebApp Template Version from settings.json with st.container():