Update modules/ui.py
Browse files- modules/ui.py +8 -25
modules/ui.py
CHANGED
|
@@ -172,27 +172,6 @@ def register_form():
|
|
| 172 |
##
|
| 173 |
##
|
| 174 |
pass
|
| 175 |
-
##################################################################################################
|
| 176 |
-
def display_chat_interface():
|
| 177 |
-
st.markdown("### Chat con AIdeaText")
|
| 178 |
-
|
| 179 |
-
if 'chat_history' not in st.session_state:
|
| 180 |
-
st.session_state.chat_history = []
|
| 181 |
-
|
| 182 |
-
for i, (role, text) in enumerate(st.session_state.chat_history):
|
| 183 |
-
if role == "user":
|
| 184 |
-
st.text_area(f"Tú:", value=text, height=50, key=f"user_message_{i}", disabled=True)
|
| 185 |
-
else:
|
| 186 |
-
st.text_area(f"AIdeaText:", value=text, height=50, key=f"bot_message_{i}", disabled=True)
|
| 187 |
-
|
| 188 |
-
user_input = st.text_input("Escribe tu mensaje aquí:")
|
| 189 |
-
|
| 190 |
-
if st.button("Enviar"):
|
| 191 |
-
if user_input:
|
| 192 |
-
st.session_state.chat_history.append(("user", user_input))
|
| 193 |
-
response = get_chatbot_response(user_input)
|
| 194 |
-
st.session_state.chat_history.append(("bot", response))
|
| 195 |
-
st.experimental_rerun()
|
| 196 |
|
| 197 |
################################################################################
|
| 198 |
# Funciones para Cosmos DB MongoDB API (análisis de texto)
|
|
@@ -697,7 +676,7 @@ def display_chatbot_interface(lang_code):
|
|
| 697 |
if user_input:
|
| 698 |
# Agregar mensaje del usuario
|
| 699 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 700 |
-
|
| 701 |
# Mostrar mensaje del usuario
|
| 702 |
with chat_container:
|
| 703 |
with st.chat_message("user"):
|
|
@@ -708,7 +687,6 @@ def display_chatbot_interface(lang_code):
|
|
| 708 |
with st.chat_message("assistant"):
|
| 709 |
message_placeholder = st.empty()
|
| 710 |
full_response = ""
|
| 711 |
-
|
| 712 |
for chunk in get_chatbot_response(st.session_state.chatbot, user_input, lang_code):
|
| 713 |
full_response += chunk
|
| 714 |
message_placeholder.markdown(full_response + "▌")
|
|
@@ -716,9 +694,14 @@ def display_chatbot_interface(lang_code):
|
|
| 716 |
|
| 717 |
# Agregar respuesta del asistente a los mensajes
|
| 718 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
| 719 |
-
|
| 720 |
# Guardar la conversación en la base de datos
|
| 721 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 722 |
|
| 723 |
# Scroll al final del chat
|
| 724 |
st.markdown('<script>window.scrollTo(0,document.body.scrollHeight);</script>', unsafe_allow_html=True)
|
|
|
|
| 172 |
##
|
| 173 |
##
|
| 174 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
################################################################################
|
| 177 |
# Funciones para Cosmos DB MongoDB API (análisis de texto)
|
|
|
|
| 676 |
if user_input:
|
| 677 |
# Agregar mensaje del usuario
|
| 678 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 679 |
+
|
| 680 |
# Mostrar mensaje del usuario
|
| 681 |
with chat_container:
|
| 682 |
with st.chat_message("user"):
|
|
|
|
| 687 |
with st.chat_message("assistant"):
|
| 688 |
message_placeholder = st.empty()
|
| 689 |
full_response = ""
|
|
|
|
| 690 |
for chunk in get_chatbot_response(st.session_state.chatbot, user_input, lang_code):
|
| 691 |
full_response += chunk
|
| 692 |
message_placeholder.markdown(full_response + "▌")
|
|
|
|
| 694 |
|
| 695 |
# Agregar respuesta del asistente a los mensajes
|
| 696 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
| 697 |
+
|
| 698 |
# Guardar la conversación en la base de datos
|
| 699 |
+
try:
|
| 700 |
+
store_chat_history(st.session_state.username, st.session_state.messages)
|
| 701 |
+
st.success("Conversación guardada exitosamente")
|
| 702 |
+
except Exception as e:
|
| 703 |
+
st.error(f"Error al guardar la conversación: {str(e)}")
|
| 704 |
+
logger.error(f"Error al guardar el historial de chat para {st.session_state.username}: {str(e)}")
|
| 705 |
|
| 706 |
# Scroll al final del chat
|
| 707 |
st.markdown('<script>window.scrollTo(0,document.body.scrollHeight);</script>', unsafe_allow_html=True)
|