Update src/streamlit_app.py
Browse files- src/streamlit_app.py +24 -9
src/streamlit_app.py
CHANGED
|
@@ -102,6 +102,7 @@ Output: Write each question on a new line. Do not invent facts β base question
|
|
| 102 |
|
| 103 |
# --- Function to activate a document from the registry ---
|
| 104 |
def activate_document(doc_name):
|
|
|
|
| 105 |
registry = st.session_state.registry
|
| 106 |
doc = registry.get_doc(doc_name)
|
| 107 |
|
|
@@ -109,21 +110,35 @@ def activate_document(doc_name):
|
|
| 109 |
st.warning(f"Document {doc_name} not found in registry.")
|
| 110 |
return
|
| 111 |
|
| 112 |
-
# Load
|
| 113 |
st.session_state.active_doc = doc
|
| 114 |
-
st.session_state.chunks = doc
|
| 115 |
-
st.session_state.embeddings = doc
|
| 116 |
-
st.session_state.index = doc
|
| 117 |
|
| 118 |
-
#
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 122 |
|
| 123 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
st.rerun()
|
| 125 |
|
| 126 |
|
|
|
|
| 127 |
# ==========================================================
|
| 128 |
# π¨ STYLING β REVERT TO ORIGINAL
|
| 129 |
# ==========================================================
|
|
|
|
| 102 |
|
| 103 |
# --- Function to activate a document from the registry ---
|
| 104 |
def activate_document(doc_name):
|
| 105 |
+
"""Load an existing registered document into the active context."""
|
| 106 |
registry = st.session_state.registry
|
| 107 |
doc = registry.get_doc(doc_name)
|
| 108 |
|
|
|
|
| 110 |
st.warning(f"Document {doc_name} not found in registry.")
|
| 111 |
return
|
| 112 |
|
| 113 |
+
# Load all available preprocessed data
|
| 114 |
st.session_state.active_doc = doc
|
| 115 |
+
st.session_state.chunks = doc.get("chunks", [])
|
| 116 |
+
st.session_state.embeddings = doc.get("embeddings")
|
| 117 |
+
st.session_state.index = doc.get("index")
|
| 118 |
|
| 119 |
+
# --- Handle TOC safely ---
|
| 120 |
+
# Some docs may not have toc saved in registry; fallback to empty list
|
| 121 |
+
toc_data = doc.get("toc", [])
|
| 122 |
+
if not toc_data:
|
| 123 |
+
st.info(f"β οΈ No TOC found for {doc_name}. Using empty TOC for suggestions.")
|
| 124 |
|
| 125 |
+
# --- Regenerate suggestions safely ---
|
| 126 |
+
try:
|
| 127 |
+
st.session_state.query_suggestions_fixed = generate_dynamic_suggestions_from_toc(
|
| 128 |
+
toc_data,
|
| 129 |
+
st.session_state.chunks,
|
| 130 |
+
doc.get("name", "Unknown Document")
|
| 131 |
+
)
|
| 132 |
+
except Exception as e:
|
| 133 |
+
# Defensive guard: even if suggestion generator fails, app won't break
|
| 134 |
+
st.warning(f"Suggestion generation failed: {e}")
|
| 135 |
+
st.session_state.query_suggestions_fixed = []
|
| 136 |
+
|
| 137 |
+
# --- Trigger a clean UI rerun so the switch shows immediately ---
|
| 138 |
st.rerun()
|
| 139 |
|
| 140 |
|
| 141 |
+
|
| 142 |
# ==========================================================
|
| 143 |
# π¨ STYLING β REVERT TO ORIGINAL
|
| 144 |
# ==========================================================
|