ngcanh commited on
Commit
67e0121
·
verified ·
1 Parent(s): db3d01b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -9
app.py CHANGED
@@ -124,17 +124,64 @@ def process_feedback(query, response, feedback):
124
 
125
  # Streamlit interface
126
 
127
- st.title("Chào mừng bạn đã đến với MBAL Chatbot")
128
- st.markdown("***")
129
- st.info('''
130
- Tôi sẽ giải đáp các thắc mắc của bạn liên quan đến các sản phẩm bảo hiểm nhân thọ của MB Ageas Life''')
131
 
132
- col1, col2 = st.columns(2)
133
 
134
- with col1:
135
- chat = st.button("Chat")
136
- if chat:
137
- st.switch_page("pages/chatbot.py")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
 
140
  st.markdown("<div style='text-align:center;'></div>", unsafe_allow_html=True)
 
124
 
125
  # Streamlit interface
126
 
127
+ # st.title("Chào mừng bạn đã đến với MBAL Chatbot")
128
+ # st.markdown("***")
129
+ # st.info('''
130
+ # Tôi sẽ giải đáp các thắc mắc của bạn liên quan đến các sản phẩm bảo hiểm nhân thọ của MB Ageas Life''')
131
 
132
+ # col1, col2 = st.columns(2)
133
 
134
+ # with col1:
135
+ # chat = st.button("Chat")
136
+ # if chat:
137
+ # st.switch_page("pages/chatbot.py")
138
+ import streamlit as st
139
+ from app import rag_query, memory, process_feedback
140
+
141
+ # st.title("🛡️ RAG Chatbot MB Ageas Life 🛡️")
142
+
143
+ # Initialize session history
144
+ if "messages" not in st.session_state:
145
+ st.session_state.messages = []
146
+
147
+ # Hiển thị lại tin nhắn cũ
148
+ for i, message in enumerate(st.session_state.messages):
149
+ with st.chat_message(message["role"]):
150
+ st.markdown(message["content"])
151
+ if message["role"] == "assistant":
152
+ col1, col2 = st.columns([1, 15])
153
+ with col1:
154
+ if st.button("👍", key=f"thumbs_up_{i}"):
155
+ process_feedback(st.session_state.messages[i-1]["content"], message["content"], True)
156
+ with col2:
157
+ if st.button("👎", key=f"thumbs_down_{i}"):
158
+ process_feedback(st.session_state.messages[i-1]["content"], message["content"], False)
159
+
160
+ # Nhận input người dùng
161
+ if prompt := st.chat_input("Ask me any question related to MBAL"):
162
+ # Hiển thị tin nhắn người dùng
163
+ st.chat_message("user").markdown(prompt)
164
+ st.session_state.messages.append({"role": "user", "content": prompt})
165
+ memory.chat_memory.add_user_message(prompt)
166
+
167
+ # Gọi hàm RAG để trả lời
168
+ response = rag_query(prompt)
169
+
170
+ # Hiển thị tin nhắn chatbot
171
+ with st.chat_message("assistant"):
172
+ st.markdown(response)
173
+ st.session_state.messages.append({"role": "assistant", "content": response})
174
+ memory.chat_memory.add_ai_message(response)
175
+
176
+ st.rerun()
177
+
178
+ # Sidebar
179
+ # with st.sidebar:
180
+ # st.header("Lựa chọn khác")
181
+ # if st.button("Xóa lịch sử chat"):
182
+ # st.session_state.messages = []
183
+ # memory.clear()
184
+ # st.rerun()
185
 
186
 
187
  st.markdown("<div style='text-align:center;'></div>", unsafe_allow_html=True)