|
16 | 16 | import plotly.graph_objects as go |
17 | 17 | import requests |
18 | 18 | import streamlit as st |
| 19 | +import streamlit.components.v1 as components |
19 | 20 | from dotenv import load_dotenv |
20 | 21 |
|
21 | 22 | from src.clients import list_providers |
@@ -291,6 +292,31 @@ def initialize_financial_advisor( |
291 | 292 | raise |
292 | 293 |
|
293 | 294 |
|
| 295 | +def _scroll_to_bottom(): |
| 296 | + """ |
| 297 | + Force scroll to bottom by targeting the specific Streamlit main container. |
| 298 | + """ |
| 299 | + js = """ |
| 300 | + <script> |
| 301 | + function forceScroll() { |
| 302 | + var scrollable_div = window.parent.document.querySelector('section.main') || |
| 303 | + window.parent.document.querySelector('.main') || |
| 304 | + window.parent.document.querySelector('[data-testid="stMain"]'); |
| 305 | +
|
| 306 | + if (scrollable_div) { |
| 307 | + scrollable_div.scrollTop = scrollable_div.scrollHeight; |
| 308 | + } |
| 309 | + } |
| 310 | +
|
| 311 | + setTimeout(forceScroll, 100); |
| 312 | + setTimeout(forceScroll, 500); |
| 313 | + setTimeout(forceScroll, 1000); |
| 314 | + setTimeout(forceScroll, 2000); |
| 315 | + </script> |
| 316 | + """ |
| 317 | + components.html(js, height=0, width=0) |
| 318 | + |
| 319 | + |
294 | 320 | def stream_text(text: str, chunk_size: int = 20): |
295 | 321 | """ |
296 | 322 | Stream text with a typing effect by displaying chunks progressively. |
@@ -1824,6 +1850,11 @@ def main(): |
1824 | 1850 | with st.chat_message(message["role"]): |
1825 | 1851 | st.markdown(message["content"]) |
1826 | 1852 |
|
| 1853 | + prompt = st.chat_input( |
| 1854 | + "Assessment completed. See the results above.", |
| 1855 | + disabled=st.session_state.conversation_completed, |
| 1856 | + ) |
| 1857 | + |
1827 | 1858 | # Show message if conversation is completed |
1828 | 1859 | if st.session_state.conversation_completed: |
1829 | 1860 | if not st.session_state.generated_portfolio: |
@@ -1912,11 +1943,13 @@ def main(): |
1912 | 1943 | "- Click 'Clear Conversation' to start a new assessment or 'Change Provider' to start over" |
1913 | 1944 | ) |
1914 | 1945 |
|
| 1946 | + _scroll_to_bottom() |
| 1947 | + |
1915 | 1948 | else: |
1916 | 1949 | logger.debug("No financial profile available to display") |
1917 | 1950 | else: |
1918 | | - # User input - only show if conversation is not completed |
1919 | | - if prompt := st.chat_input("Ask me about your finances..."): |
| 1951 | + # Handle user input ONLY if there is a prompt (i.e., not disabled) |
| 1952 | + if prompt: |
1920 | 1953 | logger.debug("User input received: %s", prompt[:100]) |
1921 | 1954 |
|
1922 | 1955 | # Display user message |
|
0 commit comments