Create pages/galatea_asistente.py
Browse files- pages/pages/galatea_asistente.py +119 -0
pages/pages/galatea_asistente.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Configurar p谩gina de Streamlit
|
| 5 |
+
st.set_page_config(page_title="Galatea Asistente", layout="wide")
|
| 6 |
+
|
| 7 |
+
# Funci贸n para inicializar el estado de la sesi贸n
|
| 8 |
+
def inicializar_estado():
|
| 9 |
+
if 'modelo' not in st.session_state:
|
| 10 |
+
st.session_state['modelo'] = "gpt-3.5-turbo"
|
| 11 |
+
if 'temperatura' not in st.session_state:
|
| 12 |
+
st.session_state['temperatura'] = 0.5
|
| 13 |
+
if 'mensajes_chat' not in st.session_state:
|
| 14 |
+
st.session_state['mensajes_chat'] = []
|
| 15 |
+
if 'transcripcion_voz' not in st.session_state:
|
| 16 |
+
st.session_state['transcripcion_voz'] = ""
|
| 17 |
+
|
| 18 |
+
inicializar_estado()
|
| 19 |
+
|
| 20 |
+
# Configuraci贸n de la barra lateral
|
| 21 |
+
st.sidebar.title("Configuraci贸n del Asistente")
|
| 22 |
+
st.sidebar.subheader("Modelo de Lenguaje")
|
| 23 |
+
st.session_state['modelo'] = st.sidebar.selectbox(
|
| 24 |
+
"Selecciona el modelo:",
|
| 25 |
+
["gpt-3.5-turbo", "gpt-4"],
|
| 26 |
+
index=0
|
| 27 |
+
)
|
| 28 |
+
st.sidebar.subheader("Ajustes del Modelo")
|
| 29 |
+
st.session_state['temperatura'] = st.sidebar.slider(
|
| 30 |
+
"Temperatura",
|
| 31 |
+
min_value=0.0, max_value=1.0,
|
| 32 |
+
value=st.session_state['temperatura'],
|
| 33 |
+
step=0.1
|
| 34 |
+
)
|
| 35 |
+
st.sidebar.text_input("Assistant ID", key="assistant_id", help="Introduce el Assistant ID del playground de OpenAI")
|
| 36 |
+
|
| 37 |
+
# Funci贸n para manejar la pregunta del usuario
|
| 38 |
+
def manejar_pregunta_usuario(pregunta_usuario):
|
| 39 |
+
st.session_state['mensajes_chat'].append({"role": "user", "content": pregunta_usuario})
|
| 40 |
+
with st.chat_message("user"):
|
| 41 |
+
st.markdown(pregunta_usuario)
|
| 42 |
+
|
| 43 |
+
# Aqu铆 debes agregar la l贸gica para obtener la respuesta del modelo
|
| 44 |
+
respuesta = "Esta es una respuesta simulada."
|
| 45 |
+
|
| 46 |
+
st.session_state['mensajes_chat'].append({"role": "assistant", "content": respuesta})
|
| 47 |
+
with st.chat_message("assistant"):
|
| 48 |
+
st.markdown(respuesta)
|
| 49 |
+
|
| 50 |
+
# Mostrar el fondo de video y superponer texto
|
| 51 |
+
st.markdown(
|
| 52 |
+
"""
|
| 53 |
+
<style>
|
| 54 |
+
#video-container {
|
| 55 |
+
position: relative;
|
| 56 |
+
width: 100%;
|
| 57 |
+
height: 90vh;
|
| 58 |
+
overflow: hidden;
|
| 59 |
+
}
|
| 60 |
+
#background-video {
|
| 61 |
+
position: absolute;
|
| 62 |
+
top: 0;
|
| 63 |
+
left: 0;
|
| 64 |
+
width: 100%;
|
| 65 |
+
height: 100%;
|
| 66 |
+
object-fit: cover;
|
| 67 |
+
z-index: -1;
|
| 68 |
+
}
|
| 69 |
+
#chat-container {
|
| 70 |
+
position: absolute;
|
| 71 |
+
top: 0;
|
| 72 |
+
left: 0;
|
| 73 |
+
width: 100%;
|
| 74 |
+
height: 100%;
|
| 75 |
+
display: flex;
|
| 76 |
+
flex-direction: column;
|
| 77 |
+
justify-content: flex-end;
|
| 78 |
+
padding: 20px;
|
| 79 |
+
box-sizing: border-box;
|
| 80 |
+
}
|
| 81 |
+
.chat-message {
|
| 82 |
+
background: rgba(255, 255, 255, 0.8);
|
| 83 |
+
border-radius: 10px;
|
| 84 |
+
padding: 10px;
|
| 85 |
+
margin-bottom: 10px;
|
| 86 |
+
max-width: 70%;
|
| 87 |
+
}
|
| 88 |
+
.chat-message.user {
|
| 89 |
+
align-self: flex-start;
|
| 90 |
+
}
|
| 91 |
+
.chat-message.assistant {
|
| 92 |
+
align-self: flex-end;
|
| 93 |
+
background: rgba(0, 123, 255, 0.8);
|
| 94 |
+
color: white;
|
| 95 |
+
}
|
| 96 |
+
</style>
|
| 97 |
+
<div id="video-container">
|
| 98 |
+
<video id="background-video" autoplay loop muted>
|
| 99 |
+
<source src="https://cdn.leonardo.ai/users/645c3d5c-ca1b-4ce8-aefa-a091494e0d09/generations/0c4f0fe7-5937-4644-b984-bdbd95018990/0c4f0fe7-5937-4644-b984-bdbd95018990.mp4" type="video/mp4">
|
| 100 |
+
</video>
|
| 101 |
+
<div id="chat-container">
|
| 102 |
+
""",
|
| 103 |
+
unsafe_allow_html=True
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# Mostrar los mensajes del chat
|
| 107 |
+
for mensaje in st.session_state['mensajes_chat']:
|
| 108 |
+
clase = "user" if mensaje["role"] == "user" else "assistant"
|
| 109 |
+
st.markdown(f'<div class="chat-message {clase}">{mensaje["content"]}</div>', unsafe_allow_html=True)
|
| 110 |
+
|
| 111 |
+
# Campo de entrada de texto para el usuario
|
| 112 |
+
pregunta_usuario = st.text_input("Escribe tu pregunta aqu铆:", key='unique_chat_input_key', value=st.session_state['transcripcion_voz'])
|
| 113 |
+
if st.button("Enviar Pregunta"):
|
| 114 |
+
manejar_pregunta_usuario(pregunta_usuario)
|
| 115 |
+
|
| 116 |
+
st.markdown("</div></div>", unsafe_allow_html=True)
|
| 117 |
+
|
| 118 |
+
# Incluir imagen de fondo (opcional)
|
| 119 |
+
st.image("/mnt/data/clara asesora.jpg", use_column_width=True)
|