Benjy commited on
Commit
873fd0b
·
verified ·
1 Parent(s): 8a716b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -22,22 +22,22 @@ def main():
22
 
23
  user_input = st.text_input("Your question:", key="user_input", on_change=submit_on_enter)
24
 
25
- if st.button("Ask") or st.session_state.get('enter_pressed', False):
26
  if user_input: # Ensuring input is not empty
27
  response = get_message(user_input)
28
  display_conversation(user_input, response)
29
 
30
  def submit_on_enter():
31
- if st.session_state.user_input: # Trigger only if there's input
32
- st.session_state.enter_pressed = True
33
- else:
34
- st.session_state.enter_pressed = False
35
 
36
  def display_conversation(user_input, response):
37
  st.session_state.history.append(f"User: {user_input}")
38
  st.session_state.history.append(f"IT Support: {response}")
39
- for message in st.session_state.history[-10:]: # Display last 10 messages
40
- st.write(message)
 
 
 
41
  st.session_state.enter_pressed = False # Reset the enter trigger
42
 
43
  def get_message(user_input):
 
22
 
23
  user_input = st.text_input("Your question:", key="user_input", on_change=submit_on_enter)
24
 
25
+ if st.session_state.get('enter_pressed', False):
26
  if user_input: # Ensuring input is not empty
27
  response = get_message(user_input)
28
  display_conversation(user_input, response)
29
 
30
  def submit_on_enter():
31
+ st.session_state.enter_pressed = True
 
 
 
32
 
33
  def display_conversation(user_input, response):
34
  st.session_state.history.append(f"User: {user_input}")
35
  st.session_state.history.append(f"IT Support: {response}")
36
+ for i, message in enumerate(st.session_state.history[-10:]): # Display last 10 messages
37
+ if i % 2 == 0:
38
+ st.markdown(f"<div style='background-color:#e1f5fe;padding:10px;border-radius:10px;'>{message}</div>", unsafe_allow_html=True)
39
+ else:
40
+ st.markdown(f"<div style='background-color:#c8e6c9;padding:10px;border-radius:10px;'>{message}</div>", unsafe_allow_html=True)
41
  st.session_state.enter_pressed = False # Reset the enter trigger
42
 
43
  def get_message(user_input):