From e6ef69b1268bcbfbb3b2a0805dcfe130e4c04b20 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Mon, 2 Feb 2026 12:59:15 +0100 Subject: [PATCH] Fix crash when navigating to a folder with no JSON files st.radio was called with an empty list when no JSON files existed, causing Streamlit to error and only render the sidebar. Co-Authored-By: Claude Opus 4.5 --- app.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 04df1fc..8600ec6 100644 --- a/app.py +++ b/app.py @@ -147,13 +147,18 @@ with st.sidebar: st.rerun() # --- File Selector --- - if 'file_selector' not in st.session_state: - st.session_state.file_selector = json_files[0].name if json_files else None - if st.session_state.file_selector not in [f.name for f in json_files] and json_files: - st.session_state.file_selector = json_files[0].name - - selected_file_name = st.radio("Select File", [f.name for f in json_files], key="file_selector") - + selected_file_name = None + if json_files: + file_names = [f.name for f in json_files] + if 'file_selector' not in st.session_state: + st.session_state.file_selector = file_names[0] + if st.session_state.file_selector not in file_names: + st.session_state.file_selector = file_names[0] + + selected_file_name = st.radio("Select File", file_names, key="file_selector") + else: + st.info("No JSON files in this folder.") + # --- GLOBAL MONITOR TOGGLE (NEW) --- st.markdown("---") show_monitor = st.checkbox("Show Comfy Monitor", value=True)