Phaneendrabayi commited on
Commit
ca4f92d
·
verified ·
1 Parent(s): b3d9785

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -112,16 +112,28 @@ st.write("Ask me anything about Data Science!")
112
  chat_container = st.container()
113
  st.markdown('<div class="chatbox">', unsafe_allow_html=True)
114
 
115
- # Display chat messages
116
- cursor.execute("SELECT message, response FROM chat_history WHERE user_id = ?", (st.session_state["user_id"],))
117
  chat_data = cursor.fetchall()
118
 
119
- for user_msg, bot_response in chat_data:
120
- st.markdown(f'<div class="user-bubble">{user_msg}</div>', unsafe_allow_html=True)
121
- st.markdown(f'<div class="bot-bubble">{bot_response}</div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
122
 
123
  st.markdown('</div>', unsafe_allow_html=True)
124
 
 
 
 
 
 
125
  # Input field for new messages
126
  st.markdown('<div class="input-container">', unsafe_allow_html=True)
127
  user_input = st.text_input("Type your message...", placeholder="Ask me a data science question")
 
112
  chat_container = st.container()
113
  st.markdown('<div class="chatbox">', unsafe_allow_html=True)
114
 
115
+ # Display chat messages with delete option
116
+ cursor.execute("SELECT id, message, response FROM chat_history WHERE user_id = ?", (st.session_state["user_id"],))
117
  chat_data = cursor.fetchall()
118
 
119
+ delete_message_id = None
120
+
121
+ for chat_id, user_msg, bot_response in chat_data:
122
+ col1, col2 = st.columns([0.9, 0.1])
123
+ with col1:
124
+ st.markdown(f'<div class="user-bubble">{user_msg}</div>', unsafe_allow_html=True)
125
+ st.markdown(f'<div class="bot-bubble">{bot_response}</div>', unsafe_allow_html=True)
126
+ with col2:
127
+ if st.button("❌", key=f"del_{chat_id}"):
128
+ delete_message_id = chat_id
129
 
130
  st.markdown('</div>', unsafe_allow_html=True)
131
 
132
+ # Delete selected message
133
+ if delete_message_id:
134
+ cursor.execute("DELETE FROM chat_history WHERE id = ?", (delete_message_id,))
135
+ conn.commit()
136
+
137
  # Input field for new messages
138
  st.markdown('<div class="input-container">', unsafe_allow_html=True)
139
  user_input = st.text_input("Type your message...", placeholder="Ask me a data science question")