Update src/streamlit_app.py
Browse files- src/streamlit_app.py +21 -5
src/streamlit_app.py
CHANGED
|
@@ -179,20 +179,34 @@ if chunks:
|
|
| 179 |
avg_len = int(sum(len(c) for c in chunks) / len(chunks))
|
| 180 |
st.caption(f"📦 {len(chunks)} chunks created | Avg chunk length: {avg_len} chars")
|
| 181 |
|
| 182 |
-
#
|
| 183 |
-
#
|
| 184 |
-
#
|
| 185 |
if index and chunks:
|
| 186 |
st.markdown("---")
|
| 187 |
st.subheader("🤖 Ask a Question")
|
| 188 |
|
| 189 |
user_query = st.text_input("🔍 Your question about the document:")
|
|
|
|
| 190 |
if user_query:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
with st.spinner("🧠 Thinking... retrieving context and generating answer..."):
|
| 192 |
retrieved = retrieve_chunks(user_query, index, chunks, top_k=top_k)
|
| 193 |
-
answer = generate_answer(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
-
# ✅ Answer
|
| 196 |
st.markdown("### ✅ Assistant’s Answer")
|
| 197 |
st.markdown(
|
| 198 |
f"<div style='background-color:#0E1117;padding:12px;border-radius:10px;color:white;'>{answer}</div>",
|
|
@@ -210,5 +224,7 @@ if index and chunks:
|
|
| 210 |
""",
|
| 211 |
unsafe_allow_html=True,
|
| 212 |
)
|
|
|
|
| 213 |
else:
|
| 214 |
st.info("📥 Upload or select a document to start exploring.")
|
|
|
|
|
|
| 179 |
avg_len = int(sum(len(c) for c in chunks) / len(chunks))
|
| 180 |
st.caption(f"📦 {len(chunks)} chunks created | Avg chunk length: {avg_len} chars")
|
| 181 |
|
| 182 |
+
# ---------------------------
|
| 183 |
+
# Query Section
|
| 184 |
+
# ---------------------------
|
| 185 |
if index and chunks:
|
| 186 |
st.markdown("---")
|
| 187 |
st.subheader("🤖 Ask a Question")
|
| 188 |
|
| 189 |
user_query = st.text_input("🔍 Your question about the document:")
|
| 190 |
+
|
| 191 |
if user_query:
|
| 192 |
+
# Show which mode is active
|
| 193 |
+
mode_label = (
|
| 194 |
+
"🧠 Reasoning Mode (expanded thinking)"
|
| 195 |
+
if st.session_state.reasoning_mode
|
| 196 |
+
else "📄 Strict Document Mode (factual only)"
|
| 197 |
+
)
|
| 198 |
+
st.caption(f"Mode: {mode_label}")
|
| 199 |
+
|
| 200 |
+
# Generate the answer
|
| 201 |
with st.spinner("🧠 Thinking... retrieving context and generating answer..."):
|
| 202 |
retrieved = retrieve_chunks(user_query, index, chunks, top_k=top_k)
|
| 203 |
+
answer = generate_answer(
|
| 204 |
+
user_query,
|
| 205 |
+
retrieved,
|
| 206 |
+
reasoning_mode=st.session_state.reasoning_mode # ✅ FIXED
|
| 207 |
+
)
|
| 208 |
|
| 209 |
+
# ✅ Display Answer
|
| 210 |
st.markdown("### ✅ Assistant’s Answer")
|
| 211 |
st.markdown(
|
| 212 |
f"<div style='background-color:#0E1117;padding:12px;border-radius:10px;color:white;'>{answer}</div>",
|
|
|
|
| 224 |
""",
|
| 225 |
unsafe_allow_html=True,
|
| 226 |
)
|
| 227 |
+
|
| 228 |
else:
|
| 229 |
st.info("📥 Upload or select a document to start exploring.")
|
| 230 |
+
|