Ademola1448 commited on
Commit
21dbf8c
1 Parent(s): e203abf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -16,10 +16,14 @@ chat = ChatOpenAI(api_key=openai_api_key)
16
  # Streamlit app setup
17
  st.title("Football Chatbot")
18
 
 
 
 
 
19
  def get_openai_response(prompt):
20
  try:
21
  response = chat([HumanMessage(content=prompt)])
22
- message = response.content.strip() # Correctly accessing the message content
23
  return message
24
  except Exception as e:
25
  return str(e)
@@ -28,13 +32,16 @@ def main():
28
  st.write("Ask anything about football and get responses from the chatbot!")
29
 
30
  user_input = st.text_input("You: ", "")
31
-
32
  if st.button("Send"):
33
  if user_input:
34
  response = get_openai_response(user_input)
35
- st.text_area("Chatbot:", value=response, height=200, max_chars=None, key=None)
36
- else:
37
- st.write("Please enter a message.")
 
 
 
38
 
39
  if __name__ == "__main__":
40
- main()
 
16
  # Streamlit app setup
17
  st.title("Football Chatbot")
18
 
19
+ # Initialize session state for conversation history
20
+ if 'history' not in st.session_state:
21
+ st.session_state.history = []
22
+
23
  def get_openai_response(prompt):
24
  try:
25
  response = chat([HumanMessage(content=prompt)])
26
+ message = response.content.strip()
27
  return message
28
  except Exception as e:
29
  return str(e)
 
32
  st.write("Ask anything about football and get responses from the chatbot!")
33
 
34
  user_input = st.text_input("You: ", "")
35
+
36
  if st.button("Send"):
37
  if user_input:
38
  response = get_openai_response(user_input)
39
+ st.session_state.history.append(("You: ", user_input))
40
+ st.session_state.history.append(("Chatbot: ", response))
41
+
42
+ # Display conversation history
43
+ for sender, message in st.session_state.history:
44
+ st.write(f"{sender} {message}")
45
 
46
  if __name__ == "__main__":
47
+ main()