From 4956b401a349c56a1f340603527d6849c6d67ac4 Mon Sep 17 00:00:00 2001 From: Daniel Plank Date: Mon, 9 Nov 2026 22:00:45 +0100 Subject: [PATCH] Streamlit UI polish: native theming, multi-chat sessions, follow-ups Fix the dark/brownish custom theme by dropping the custom [theme] config entirely and relying on Streamlit's native light/dark switcher instead (a custom theme block hides that switcher outright - confirmed by reading the compiled frontend JS). Only the native "Deploy" toolbar button is hidden now, via scoped CSS on its own test id. Move the example questions above the chat input and auto-hide them once a real message is sent in that session (rendered through components.v1.html so its script can reach across to the chat input's textarea directly and react live to theme switches via a MutationObserver, instead of st.markdown which strips + + +""", + height=40 + 48 * len(questions), + ) + + +def render_try_asking() -> None: + render_question_chips("Try asking", EXAMPLE_QUESTIONS) + + +def main() -> None: + _init_sessions() + docs = load_markdown_files() + + header_col, menu_col = st.columns([10, 1]) + with header_col: + st.title("Internal Policy & Support Assistant") + st.caption( + "Agentic RAG prototype over synthetic HR/IT/Finance/Legal policy documents - " + "ask a policy question, calculate your PTO balance, or open a support ticket." + ) + with menu_col: + if st.button("Config", use_container_width=True): + show_config_dialog(docs) force_rebuild = st.session_state.pop("_force_rebuild", False) try: @@ -82,17 +305,27 @@ def main() -> None: ) st.stop() - if "history" not in st.session_state: - st.session_state["history"] = [] + active_session = st.session_state["sessions"][st.session_state["active_session_id"]] + active_session_id = st.session_state["active_session_id"] - for turn in st.session_state["history"]: + user_query = st.chat_input(CHAT_INPUT_PLACEHOLDER) + + history = active_session["history"] + is_appending_new_turn = bool(user_query) + + for idx, turn in enumerate(history): with st.chat_message("user"): st.write(turn["query"]) with st.chat_message("assistant"): st.write(turn["answer"]) render_trace(turn["state"]) + st.feedback("thumbs", key=f"feedback_{active_session_id}_{idx}") + if idx == len(history) - 1 and not is_appending_new_turn: + render_question_chips("You might also ask", turn.get("followups", [])) + + if not history and not user_query: + render_try_asking() - user_query = st.chat_input("Ask about company policy, your PTO balance, or open a ticket...") if user_query: with st.chat_message("user"): st.write(user_query) @@ -109,7 +342,15 @@ def main() -> None: answer = state.get("final_answer", "(no answer produced)") st.write(answer) render_trace(state) - st.session_state["history"].append({"query": user_query, "answer": answer, "state": state}) + with st.spinner("Generating follow-up suggestions..."): + followups = generate_followups(get_followup_llm(), user_query, answer) + st.feedback("thumbs", key=f"feedback_{active_session_id}_{len(history)}") + render_question_chips("You might also ask", followups) + active_session["history"].append( + {"query": user_query, "answer": answer, "state": state, "followups": followups} + ) + + render_sidebar() if __name__ == "__main__": -- 2.45.3