Update modules/ui.py
Browse files- modules/ui.py +16 -14
modules/ui.py
CHANGED
@@ -420,38 +420,40 @@ def display_chatbot_interface(lang_code):
|
|
420 |
if 'messages' not in st.session_state:
|
421 |
st.session_state.messages = [{"role": "assistant", "content": t['initial_message']}]
|
422 |
|
423 |
-
# Contenedor para el chat
|
424 |
chat_container = st.container()
|
425 |
|
426 |
-
# Mostrar
|
427 |
with chat_container:
|
428 |
for message in st.session_state.messages:
|
429 |
with st.chat_message(message["role"]):
|
430 |
-
st.
|
431 |
|
432 |
-
# Área de entrada del usuario
|
433 |
user_input = st.chat_input(t['input_placeholder'])
|
434 |
|
435 |
-
# Procesamiento del input del usuario
|
436 |
if user_input:
|
437 |
# Agregar mensaje del usuario
|
438 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
439 |
-
|
440 |
-
|
|
|
|
|
|
|
441 |
|
442 |
-
# Generar
|
443 |
-
with chat_container:
|
444 |
with st.chat_message("assistant"):
|
445 |
-
message_placeholder = st.empty()
|
446 |
full_response = ""
|
447 |
-
|
448 |
-
for chunk in get_chatbot_response(st.session_state.chatbot,
|
449 |
full_response += chunk
|
450 |
message_placeholder.markdown(full_response + "▌")
|
451 |
message_placeholder.markdown(full_response)
|
452 |
-
|
453 |
# Agregar respuesta del asistente a los mensajes
|
454 |
-
st.session_state.messages.append({"role": "assistant", "content":
|
455 |
|
456 |
# Guardar la conversación en la base de datos
|
457 |
store_chat_history(st.session_state.username, st.session_state.messages)
|
|
|
420 |
if 'messages' not in st.session_state:
|
421 |
st.session_state.messages = [{"role": "assistant", "content": t['initial_message']}]
|
422 |
|
423 |
+
# Contenedor principal para el chat
|
424 |
chat_container = st.container()
|
425 |
|
426 |
+
# Mostrar mensajes existentes
|
427 |
with chat_container:
|
428 |
for message in st.session_state.messages:
|
429 |
with st.chat_message(message["role"]):
|
430 |
+
st.markdown(message["content"])
|
431 |
|
432 |
+
# Área de entrada del usuario
|
433 |
user_input = st.chat_input(t['input_placeholder'])
|
434 |
|
|
|
435 |
if user_input:
|
436 |
# Agregar mensaje del usuario
|
437 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
438 |
+
|
439 |
+
# Mostrar mensaje del usuario
|
440 |
+
with chat_container:
|
441 |
+
with st.chat_message("user"):
|
442 |
+
st.markdown(user_input)
|
443 |
|
444 |
+
# Generar respuesta del chatbot
|
445 |
+
with chat_container:
|
446 |
with st.chat_message("assistant"):
|
447 |
+
message_placeholder = st.empty()
|
448 |
full_response = ""
|
449 |
+
|
450 |
+
for chunk in get_chatbot_response(st.session_state.chatbot, user_input, lang_code):
|
451 |
full_response += chunk
|
452 |
message_placeholder.markdown(full_response + "▌")
|
453 |
message_placeholder.markdown(full_response)
|
454 |
+
|
455 |
# Agregar respuesta del asistente a los mensajes
|
456 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
457 |
|
458 |
# Guardar la conversación en la base de datos
|
459 |
store_chat_history(st.session_state.username, st.session_state.messages)
|