chatbot / app.py
Segizu's picture
Chatbot creation 1
095d11a
raw
history blame
1.52 kB
import streamlit as st
from utils import get_bot_response
# Configuración de la página
st.set_page_config(page_title="Chatbot de Servicios Digitales", layout="centered")
# Título de la app
st.title("Chatbot de Servicios Digitales")
st.write("¡Hola! Soy tu asistente virtual. Estoy aquí para ayudarte con servicios de desarrollo web, apps móviles, ideas de IA y análisis con Power BI.")
# Inicializar el historial de chat en la sesión
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
# Función para mostrar el historial de mensajes
def display_chat():
for chat in st.session_state.chat_history:
if chat["role"] == "user":
st.markdown(f"**Tú:** {chat['message']}")
else:
st.markdown(f"**Bot:** {chat['message']}")
# Mostrar la conversación previa
display_chat()
# Formulario para enviar nuevos mensajes
with st.form(key="chat_form", clear_on_submit=True):
user_input = st.text_input("Escribe tu mensaje aquí:")
submit_button = st.form_submit_button(label="Enviar")
if submit_button and user_input:
# Agregar mensaje del usuario al historial
st.session_state.chat_history.append({"role": "user", "message": user_input})
# Obtener respuesta del bot desde utils.py
bot_response = get_bot_response(user_input)
st.session_state.chat_history.append({"role": "bot", "message": bot_response})
# Al no usar experimental_rerun, el script se volverá a ejecutar automáticamente en la siguiente interacción