LohithGummi commited on
Commit
3efc5a6
·
verified ·
1 Parent(s): 4176457

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -42,7 +42,6 @@ db = SQLDatabase.from_uri(f"sqlite:///{db_loc}")
42
  # Retrieve the schema information of the database tables
43
  database_schema = db.get_table_info()
44
 
45
- st.write(database_schema)
46
 
47
  #=================================Logging=====================================#
48
 
@@ -395,21 +394,16 @@ def chat_with_agent():
395
  if 'conversation_history' not in st.session_state:
396
  st.session_state.conversation_history = [{"role": "assistant", "content": "Hey, how can I help you?"}]
397
 
398
- # Display the initial greeting
399
  for message in st.session_state.conversation_history:
400
- if message['role'] == 'assistant':
401
- st.write(f"Chatbot: {message['content']}")
402
- else:
403
- st.write(f"You: {message['content']}")
404
-
405
- user_input = st.text_input("You: ", key="user_input")
406
-
407
- if st.button("Send"):
408
- if user_input.lower() == "exit":
409
- st.write("Chatbot: Thank you for chatting. Goodbye!")
410
- return
411
-
412
- # Add user input to conversation history
413
  st.session_state.conversation_history.append({"role": "user", "content": user_input})
414
 
415
  conversation_input = "\n".join(
@@ -423,7 +417,11 @@ def chat_with_agent():
423
  st.session_state.conversation_history.append({"role": "assistant", "content": chatbot_response})
424
 
425
  # Display the chatbot's response
426
- st.write(f"Chatbot: {chatbot_response}")
 
 
 
 
427
 
428
  if __name__ == "__main__":
429
  chat_with_agent()
 
42
  # Retrieve the schema information of the database tables
43
  database_schema = db.get_table_info()
44
 
 
45
 
46
  #=================================Logging=====================================#
47
 
 
394
  if 'conversation_history' not in st.session_state:
395
  st.session_state.conversation_history = [{"role": "assistant", "content": "Hey, how can I help you?"}]
396
 
397
+ # Display chat messages from history on app rerun
398
  for message in st.session_state.conversation_history:
399
+ with st.chat_message(message["role"]):
400
+ st.markdown(message["content"])
401
+
402
+ # React to user input
403
+ if user_input := st.chat_input("You: "):
404
+ # Display user message in chat message container
405
+ st.chat_message("user").markdown(user_input)
406
+ # Add user message to conversation history
 
 
 
 
 
407
  st.session_state.conversation_history.append({"role": "user", "content": user_input})
408
 
409
  conversation_input = "\n".join(
 
417
  st.session_state.conversation_history.append({"role": "assistant", "content": chatbot_response})
418
 
419
  # Display the chatbot's response
420
+ with st.chat_message("assistant"):
421
+ st.markdown(chatbot_response)
422
+
423
+ if __name__ == "__main__":
424
+ chat_with_agent()
425
 
426
  if __name__ == "__main__":
427
  chat_with_agent()