Update src/streamlit_app.py
Browse files- src/streamlit_app.py +31 -10
src/streamlit_app.py
CHANGED
|
@@ -212,7 +212,7 @@ st.caption("Query SAP documentation and enterprise PDFs β powered by reasoning
|
|
| 212 |
doc_choice = st.radio("Select a document:", ["-- Select --", "Sample PDF", "Upload Custom PDF"], index=0)
|
| 213 |
|
| 214 |
# ==========================================================
|
| 215 |
-
# π DOCUMENT HANDLING β CLEAN + ACCURATE UI FLOW (final
|
| 216 |
# ==========================================================
|
| 217 |
if doc_choice == "-- Select --":
|
| 218 |
st.info("β¬
οΈ Select or upload a document to begin.")
|
|
@@ -253,13 +253,13 @@ else:
|
|
| 253 |
embeddings = cache_embeddings(doc_name, chunks, embed_chunks)
|
| 254 |
index = build_faiss_index(embeddings)
|
| 255 |
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
)
|
| 260 |
-
status.
|
| 261 |
|
| 262 |
-
#
|
| 263 |
st.session_state.update({
|
| 264 |
"text": text,
|
| 265 |
"toc": toc,
|
|
@@ -268,7 +268,7 @@ else:
|
|
| 268 |
"index": index,
|
| 269 |
"doc_ready": True,
|
| 270 |
"last_doc": doc_name,
|
| 271 |
-
"status_text":
|
| 272 |
})
|
| 273 |
|
| 274 |
# Build suggestions once
|
|
@@ -280,14 +280,34 @@ else:
|
|
| 280 |
st.rerun()
|
| 281 |
|
| 282 |
else:
|
| 283 |
-
# Reuse cached content and
|
| 284 |
text = st.session_state["text"]
|
| 285 |
toc = st.session_state["toc"]
|
| 286 |
chunks = st.session_state["chunks"]
|
| 287 |
embeddings = st.session_state["embeddings"]
|
| 288 |
index = st.session_state["index"]
|
| 289 |
query_suggestions = st.session_state.get("query_suggestions_fixed", [])
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
# --- Ask section ---
|
| 293 |
st.markdown("### π¬ Ask the Assistant")
|
|
@@ -320,6 +340,7 @@ else:
|
|
| 320 |
st.markdown(f"<div class='answer-box'>{answer}</div>", unsafe_allow_html=True)
|
| 321 |
|
| 322 |
|
|
|
|
| 323 |
# ==========================================================
|
| 324 |
# π¨ Optional Sidebar Scroll Styling (keeps it clean)
|
| 325 |
# ==========================================================
|
|
|
|
| 212 |
doc_choice = st.radio("Select a document:", ["-- Select --", "Sample PDF", "Upload Custom PDF"], index=0)
|
| 213 |
|
| 214 |
# ==========================================================
|
| 215 |
+
# π DOCUMENT HANDLING β CLEAN + ACCURATE UI FLOW (final polished)
|
| 216 |
# ==========================================================
|
| 217 |
if doc_choice == "-- Select --":
|
| 218 |
st.info("β¬
οΈ Select or upload a document to begin.")
|
|
|
|
| 253 |
embeddings = cache_embeddings(doc_name, chunks, embed_chunks)
|
| 254 |
index = build_faiss_index(embeddings)
|
| 255 |
|
| 256 |
+
# β
Smooth transition for ready state
|
| 257 |
+
import time
|
| 258 |
+
status.success("β
Document processed successfully.")
|
| 259 |
+
time.sleep(1.2)
|
| 260 |
+
status.empty()
|
| 261 |
|
| 262 |
+
# β
Simplified final ready message for reruns
|
| 263 |
st.session_state.update({
|
| 264 |
"text": text,
|
| 265 |
"toc": toc,
|
|
|
|
| 268 |
"index": index,
|
| 269 |
"doc_ready": True,
|
| 270 |
"last_doc": doc_name,
|
| 271 |
+
"status_text": f"π {doc_name} ready β your AI assistant is standing by!"
|
| 272 |
})
|
| 273 |
|
| 274 |
# Build suggestions once
|
|
|
|
| 280 |
st.rerun()
|
| 281 |
|
| 282 |
else:
|
| 283 |
+
# Reuse cached content and show final ready message with fade-in
|
| 284 |
text = st.session_state["text"]
|
| 285 |
toc = st.session_state["toc"]
|
| 286 |
chunks = st.session_state["chunks"]
|
| 287 |
embeddings = st.session_state["embeddings"]
|
| 288 |
index = st.session_state["index"]
|
| 289 |
query_suggestions = st.session_state.get("query_suggestions_fixed", [])
|
| 290 |
+
|
| 291 |
+
# β¨ Fading "ready" message for better UX
|
| 292 |
+
st.markdown(f"""
|
| 293 |
+
<div style="
|
| 294 |
+
animation: fadeIn 1.2s ease-in-out;
|
| 295 |
+
background: #072541;
|
| 296 |
+
border-left: 4px solid #10b981;
|
| 297 |
+
padding: 10px 14px;
|
| 298 |
+
border-radius: 6px;
|
| 299 |
+
color: #d1fae5;
|
| 300 |
+
margin-top: 8px;
|
| 301 |
+
font-size: 15px;">
|
| 302 |
+
β
{st.session_state.get('status_text', f"{doc_name} ready for queries.")}
|
| 303 |
+
</div>
|
| 304 |
+
<style>
|
| 305 |
+
@keyframes fadeIn {{
|
| 306 |
+
from {{opacity: 0; transform: translateY(-4px);}}
|
| 307 |
+
to {{opacity: 1; transform: translateY(0);}}
|
| 308 |
+
}}
|
| 309 |
+
</style>
|
| 310 |
+
""", unsafe_allow_html=True)
|
| 311 |
|
| 312 |
# --- Ask section ---
|
| 313 |
st.markdown("### π¬ Ask the Assistant")
|
|
|
|
| 340 |
st.markdown(f"<div class='answer-box'>{answer}</div>", unsafe_allow_html=True)
|
| 341 |
|
| 342 |
|
| 343 |
+
|
| 344 |
# ==========================================================
|
| 345 |
# π¨ Optional Sidebar Scroll Styling (keeps it clean)
|
| 346 |
# ==========================================================
|