File size: 1,558 Bytes
cc12747
 
 
 
 
 
c9b8157
cc12747
 
 
c9b8157
 
 
 
 
 
cc12747
c9b8157
90e359d
cc12747
c9b8157
 
90e359d
c9b8157
 
 
90e359d
c9b8157
 
90e359d
c9b8157
 
 
 
 
 
 
cc12747
90e359d
 
c9b8157
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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")

# Inicializar el historial del chat en la sesi贸n
if "chat_history" not in st.session_state:
    st.session_state.chat_history = []

# T铆tulo y mensaje de bienvenida
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."
)

# Campo de texto para ingresar el mensaje del usuario (usando una key para poder manipular su valor)
user_input = st.text_input("Escribe tu mensaje aqu铆:")

# Bot贸n de env铆o
if st.button("Enviar"):
    if user_input:  # Verifica que se haya escrito algo
        # Agregar el mensaje del usuario al historial
        st.session_state.chat_history.append({
            "role": "user",
            "message": user_input
        })
        # Obtener respuesta del bot y agregarla al historial
        response = get_bot_response(user_input)
        st.session_state.chat_history.append({
            "role": "bot",
            "message": response
        })
        # Forzar la actualizaci贸n de la interfaz
    else:
        st.warning("Por favor, ingresa un mensaje.")

# Mostrar el historial actualizado del cha
# 
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']}")