JohnAlexander23 commited on
Commit
4ff2cb5
·
verified ·
1 Parent(s): 76f7219

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -76,30 +76,27 @@ st.markdown(
76
  st.title("Fastest AI Chatbot")
77
  st.write("Ask a question and get a response.")
78
 
 
 
 
 
 
 
 
 
79
  # Display chat history
80
- for chat in st.session_state.chat_history:
81
- if chat["role"] == "user":
82
- st.markdown(f"**You:** {chat['content']}")
83
- elif chat["role"] == "assistant":
84
- st.markdown(f"**AI:** {chat['content']}")
85
 
86
  # Text input for user's question
87
- user_input = st.text_input("Enter your question here:")
88
 
89
  # Button to trigger response
90
  if st.button("Get Response"):
91
  if user_input:
92
  # Fetch and display response
93
  response = fetch_response(user_input)
94
- st.session_state.chat_history.append({"role": "user", "content": user_input})
95
- st.session_state.chat_history.append({"role": "assistant", "content": response})
96
-
97
- # Display new chat history without refreshing
98
  st.experimental_rerun()
99
 
100
- # Display input field at the end
101
- st.text_input("Enter your question here:", key="input")
102
-
103
  # Footer
104
  st.markdown(
105
  """
 
76
  st.title("Fastest AI Chatbot")
77
  st.write("Ask a question and get a response.")
78
 
79
+ # Function to display chat history
80
+ def display_chat_history():
81
+ for chat in st.session_state.chat_history:
82
+ if chat["role"] == "user":
83
+ st.markdown(f"**You:** {chat['content']}")
84
+ elif chat["role"] == "assistant":
85
+ st.markdown(f"**AI:** {chat['content']}")
86
+
87
  # Display chat history
88
+ display_chat_history()
 
 
 
 
89
 
90
  # Text input for user's question
91
+ user_input = st.text_input("Enter your question here:", key="input")
92
 
93
  # Button to trigger response
94
  if st.button("Get Response"):
95
  if user_input:
96
  # Fetch and display response
97
  response = fetch_response(user_input)
 
 
 
 
98
  st.experimental_rerun()
99
 
 
 
 
100
  # Footer
101
  st.markdown(
102
  """