AlanOC commited on
Commit
ef31134
·
verified ·
1 Parent(s): afb9a8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -228,6 +228,7 @@ def main():
228
 
229
 
230
 
 
231
  st.markdown(
232
  """
233
  <style>
@@ -249,9 +250,11 @@ def main():
249
  """, unsafe_allow_html=True
250
  )
251
 
 
252
  if "chat_history" not in st.session_state:
253
- st.session_state.chat_history = list()
254
 
 
255
  with st.form("input_form"):
256
  "*Enter messages here*"
257
 
@@ -259,17 +262,24 @@ def main():
259
 
260
  with col1:
261
  message = st.text_input("message", label_visibility="collapsed")
262
-
263
- if message:
264
- st.session_state.chat_history.append(f"{datetime.now().strftime(r'%H:%M:%S')}: {message}")
265
 
266
  with col2:
267
  submitted = st.form_submit_button(use_container_width=True)
268
 
269
- if submitted:
270
- for msg in st.session_state.chat_history:
271
- with st.chat_message("user", avatar="🤪"):
272
- st.write(msg)
 
 
 
 
 
 
 
 
 
 
273
 
274
 
275
 
 
228
 
229
 
230
 
231
+ # Custom CSS
232
  st.markdown(
233
  """
234
  <style>
 
250
  """, unsafe_allow_html=True
251
  )
252
 
253
+ # Initialize chat history
254
  if "chat_history" not in st.session_state:
255
+ st.session_state.chat_history = []
256
 
257
+ # Form for user input
258
  with st.form("input_form"):
259
  "*Enter messages here*"
260
 
 
262
 
263
  with col1:
264
  message = st.text_input("message", label_visibility="collapsed")
 
 
 
265
 
266
  with col2:
267
  submitted = st.form_submit_button(use_container_width=True)
268
 
269
+ # Process and append user message and response to chat history
270
+ if submitted and message:
271
+ user_msg = f"{datetime.now().strftime(r'%H:%M:%S')}: You: {message}"
272
+ st.session_state.chat_history.append(user_msg)
273
+
274
+ # Get response from the processing function
275
+ response = ask_alans_ai(message)
276
+ response_msg = f"{datetime.now().strftime(r'%H:%M:%S')}: Bot: {response}"
277
+ st.session_state.chat_history.append(response_msg)
278
+
279
+ # Display chat history
280
+ for msg in st.session_state.chat_history:
281
+ with st.chat_message("user", avatar="🤪"):
282
+ st.write(msg)
283
 
284
 
285