Spaces:
Sleeping
Sleeping
Create chat_interface.py
Browse files
modules/chatbot/chat_interface.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# chatbot/chat_interface.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from .chatbot import AIdeaTextChatbot
|
| 4 |
+
|
| 5 |
+
def display_chat_interface(lang_code: str, chat_translations: Dict):
|
| 6 |
+
"""
|
| 7 |
+
Muestra la interfaz del chat
|
| 8 |
+
"""
|
| 9 |
+
# Inicializar chatbot si no existe
|
| 10 |
+
if 'chatbot' not in st.session_state:
|
| 11 |
+
st.session_state.chatbot = AIdeaTextChatbot(lang_code)
|
| 12 |
+
|
| 13 |
+
# Mostrar historial
|
| 14 |
+
for msg in st.session_state.chatbot.get_conversation_history():
|
| 15 |
+
with st.chat_message(msg[0]):
|
| 16 |
+
st.write(msg[1])
|
| 17 |
+
|
| 18 |
+
# Input del usuario
|
| 19 |
+
if prompt := st.chat_input(chat_translations.get('chat_placeholder', 'Escribe tu mensaje...')):
|
| 20 |
+
# Procesar mensaje
|
| 21 |
+
response = st.session_state.chatbot.process_message(prompt)
|
| 22 |
+
|
| 23 |
+
# Mostrar respuesta
|
| 24 |
+
with st.chat_message("assistant"):
|
| 25 |
+
st.write(response)
|