From 255ad7c2231fb2a733c71f92a4dff8fd6caa5506 Mon Sep 17 00:00:00 2001 From: Martin Lehmann Date: Mon, 29 Jan 2024 14:44:04 +0100 Subject: [PATCH 1/2] feat: Show a spinner while loading the model Loading big models can take a couple seconds. Show a spinner to make it more apparent that things aren't stuck. --- capella_model_explorer/demo.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/capella_model_explorer/demo.py b/capella_model_explorer/demo.py index f90b444..fb6b5c3 100644 --- a/capella_model_explorer/demo.py +++ b/capella_model_explorer/demo.py @@ -45,17 +45,17 @@ def red_text(text): if not model_name: st.stop() -if ( - "model_name" not in st.session_state - or st.session_state["model_name"] != model_name -): +if st.session_state.get("model_name") != model_name: all_models = st.session_state["all_models"] st.session_state.clear() st.session_state["all_models"] = all_models - st.session_state["model"] = capellambse.MelodyModel( - st.session_state["all_models"][model_name] - ) - st.session_state["model_name"] = model_name + + with st.sidebar, st.spinner(f"Loading {model_name}..."): + st.session_state["model"] = capellambse.MelodyModel( + st.session_state["all_models"][model_name] + ) + st.session_state["model_name"] = model_name + model = st.session_state["model"] with st.sidebar: st.write(f"Loaded model {model.name!r}") From 2e07f2749b44999f4dde652876dba90d69c39ddb Mon Sep 17 00:00:00 2001 From: Martin Lehmann Date: Mon, 29 Jan 2024 14:47:37 +0100 Subject: [PATCH 2/2] feat: Reload the model after explicit clearing When the user clicks the X button in the model selection box, eagerly evict the model from the session. This allows to explicitly reload the model from disk, even when there is only one model to choose from. --- capella_model_explorer/demo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/capella_model_explorer/demo.py b/capella_model_explorer/demo.py index fb6b5c3..a34d833 100644 --- a/capella_model_explorer/demo.py +++ b/capella_model_explorer/demo.py @@ -43,6 +43,8 @@ def red_text(text): ) if not model_name: + st.session_state["model_name"] = None + st.session_state["model"] = None st.stop() if st.session_state.get("model_name") != model_name: