philipk22 commited on
Commit
5a2107b
·
1 Parent(s): aa7278e

update streamlit_app.py 2

Browse files
Files changed (1) hide show
  1. streamlit_app.py +18 -7
streamlit_app.py CHANGED
@@ -41,8 +41,13 @@ def main():
41
 
42
  # Display chat history
43
  for message in st.session_state.messages:
44
- with st.chat_message(message["role"]):
45
- st.markdown(message["content"])
 
 
 
 
 
46
 
47
  # Chat input and response handling
48
  # Check if st.chat_input is available (Streamlit 1.2 or higher)
@@ -55,13 +60,19 @@ def main():
55
  st.session_state.messages.append({"role": "user", "content": prompt})
56
 
57
  # Display user message
58
- with st.chat_message("user"):
59
- st.markdown(prompt)
 
 
 
60
 
61
  # Generate response (cached if already asked before)
62
- with st.chat_message("assistant"):
63
- response = cached_response(prompt)
64
- st.markdown(response)
 
 
 
65
 
66
  # Store bot response in chat history
67
  st.session_state.messages.append({"role": "assistant", "content": response})
 
41
 
42
  # Display chat history
43
  for message in st.session_state.messages:
44
+ role = message["role"]
45
+ content = message["content"]
46
+ if hasattr(st, "chat_message"):
47
+ with st.chat_message(role):
48
+ st.markdown(content)
49
+ else:
50
+ st.write(f"**{role.capitalize()}:** {content}")
51
 
52
  # Chat input and response handling
53
  # Check if st.chat_input is available (Streamlit 1.2 or higher)
 
60
  st.session_state.messages.append({"role": "user", "content": prompt})
61
 
62
  # Display user message
63
+ if hasattr(st, "chat_message"):
64
+ with st.chat_message("user"):
65
+ st.markdown(prompt)
66
+ else:
67
+ st.write(f"**User:** {prompt}")
68
 
69
  # Generate response (cached if already asked before)
70
+ if hasattr(st, "chat_message"):
71
+ with st.chat_message("assistant"):
72
+ response = cached_response(prompt)
73
+ st.markdown(response)
74
+ else:
75
+ st.write(f"**Assistant:** {response}")
76
 
77
  # Store bot response in chat history
78
  st.session_state.messages.append({"role": "assistant", "content": response})