File size: 1,486 Bytes
cc12747
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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})
    # Recargar la app para actualizar el historial
    st.experimental_rerun()