Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +16 -8
src/streamlit_app.py
CHANGED
|
@@ -76,8 +76,10 @@ st.title("🤖 cAsh Robo-Advisor")
|
|
| 76 |
st.markdown("---")
|
| 77 |
|
| 78 |
# Initialize Chat History
|
| 79 |
-
if "messages" not in st.session_state:
|
| 80 |
-
st.session_state.messages = [
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Sidebar Examples
|
| 83 |
st.sidebar.header("Example Queries")
|
|
@@ -93,16 +95,22 @@ for ex in examples:
|
|
| 93 |
if st.sidebar.button(ex):
|
| 94 |
asyncio.run(process_chat(ex))
|
| 95 |
|
|
|
|
|
|
|
|
|
|
| 96 |
# --- 5. Main Chat Interface ---
|
| 97 |
# Display existing messages
|
| 98 |
-
for message in st.session_state.messages:
|
| 99 |
with st.chat_message(message["role"]):
|
| 100 |
-
st.
|
| 101 |
|
| 102 |
# User Input
|
| 103 |
-
if
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
asyncio.run(process_chat(prompt))
|
|
|
|
| 76 |
st.markdown("---")
|
| 77 |
|
| 78 |
# Initialize Chat History
|
| 79 |
+
if "messages" not in st.session_state.keys(): # Initialize the chat messages history
|
| 80 |
+
st.session_state.messages = [
|
| 81 |
+
{"role": "assistant", "content": "Ask me a question about investing in Pokemon Cards!"}
|
| 82 |
+
]
|
| 83 |
|
| 84 |
# Sidebar Examples
|
| 85 |
st.sidebar.header("Example Queries")
|
|
|
|
| 95 |
if st.sidebar.button(ex):
|
| 96 |
asyncio.run(process_chat(ex))
|
| 97 |
|
| 98 |
+
if prompt := st.chat_input("Your question"): # Prompt for user input and save to chat history
|
| 99 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 100 |
+
|
| 101 |
# --- 5. Main Chat Interface ---
|
| 102 |
# Display existing messages
|
| 103 |
+
for message in st.session_state.messages: # Display the prior chat messages
|
| 104 |
with st.chat_message(message["role"]):
|
| 105 |
+
st.write(message["content"])
|
| 106 |
|
| 107 |
# User Input
|
| 108 |
+
if st.session_state.messages[-1]["role"] != "assistant":
|
| 109 |
+
with st.chat_message("assistant"):
|
| 110 |
+
with st.spinner("Thinking..."):
|
| 111 |
+
response = st.session_state.chat_engine.chat(prompt)
|
| 112 |
+
st.write(response.response)
|
| 113 |
+
message = {"role": "assistant", "content": response.response}
|
| 114 |
+
st.session_state.messages.append(message) # Add response to message history
|
| 115 |
|
| 116 |
asyncio.run(process_chat(prompt))
|