Benjy commited on
Commit
cc5db75
·
verified ·
1 Parent(s): a99d6b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -13,30 +13,29 @@ openai.api_key = os.getenv("API_KEY")
13
  def main():
14
  st.title("Tech Support Chatbot")
15
  st.text(" ")
16
- st.text("This is a demo of a customised tech support chatbot.")
17
 
18
  # Initialize or continue the session's conversation history
19
  if 'history' not in st.session_state:
20
  st.session_state.history = []
21
-
 
 
22
  # User input with a unique key that gets reset
23
- user_input = st.text_input("Tell us what's happening:", key="user_input")
24
-
25
- # Submit button
26
- if st.button("Submit"):
27
- if user_input: # Ensuring input is not empty
28
- response = get_message(user_input)
29
- display_conversation(user_input, response)
30
- st.session_state.user_input = "" # Clear the input after submission
31
 
32
  # Display the conversation history
33
- display_conversation(None, None)
34
 
35
- def display_conversation(user_input, response):
36
- if user_input and response:
 
 
37
  st.session_state.history.append(f"User: {user_input}")
38
  st.session_state.history.append(f"IT Support: {response}")
39
-
 
 
40
  for i, message in enumerate(st.session_state.history[-10:]): # Display last 10 messages
41
  if i % 2 == 0:
42
  st.markdown(f"<div style='background-color:#e1f5fe;padding:10px;border-radius:10px;'>{message}</div>&nbsp;", unsafe_allow_html=True)
 
13
  def main():
14
  st.title("Tech Support Chatbot")
15
  st.text(" ")
16
+ st.text("This is a demo of a customised tech support chatbot for ACME INC.")
17
 
18
  # Initialize or continue the session's conversation history
19
  if 'history' not in st.session_state:
20
  st.session_state.history = []
21
+ if 'input_text' not in st.session_state:
22
+ st.session_state.input_text = ""
23
+
24
  # User input with a unique key that gets reset
25
+ user_input = st.text_input("Tell us what's happening:", key="input_text", on_change=handle_input)
 
 
 
 
 
 
 
26
 
27
  # Display the conversation history
28
+ display_conversation()
29
 
30
+ def handle_input():
31
+ user_input = st.session_state.input_text
32
+ if user_input:
33
+ response = get_message(user_input)
34
  st.session_state.history.append(f"User: {user_input}")
35
  st.session_state.history.append(f"IT Support: {response}")
36
+ st.session_state.input_text = "" # Clear the input after submission
37
+
38
+ def display_conversation():
39
  for i, message in enumerate(st.session_state.history[-10:]): # Display last 10 messages
40
  if i % 2 == 0:
41
  st.markdown(f"<div style='background-color:#e1f5fe;padding:10px;border-radius:10px;'>{message}</div>&nbsp;", unsafe_allow_html=True)