| import streamlit as st |
| import os |
| import PyPDF2 |
|
|
| |
| st.set_page_config(page_title="Galatea Asistente", layout="wide") |
|
|
| |
| def inicializar_estado(): |
| if 'modelo' not in st.session_state: |
| st.session_state['modelo'] = "gpt-4-turbo" |
| if 'temperatura' not in st.session_state: |
| st.session_state['temperatura'] = 0.5 |
| if 'mensajes_chat' not in st.session_state: |
| st.session_state['mensajes_chat'] = [] |
| if 'transcripcion_voz' not in st.session_state: |
| st.session_state['transcripcion_voz'] = "" |
| if 'pdf_texto' not in st.session_state: |
| st.session_state['pdf_texto'] = "" |
|
|
| inicializar_estado() |
|
|
| |
| def cargar_pdf(path): |
| texto = "" |
| with open(path, "rb") as archivo: |
| lector_pdf = PyPDF2.PdfFileReader(archivo) |
| for pagina in range(lector_pdf.getNumPages()): |
| texto += lector_pdf.getPage(pagina).extract_text() |
| return texto |
|
|
| |
| ruta_pdf = "/assets/INSTRUCCIONES PROMPT GALATEA.pdf" |
| st.session_state['pdf_texto'] = cargar_pdf(ruta_pdf) |
|
|
| |
| st.sidebar.title("Configuraci贸n del Asistente") |
| st.sidebar.subheader("Modelo de Lenguaje") |
| st.session_state['modelo'] = st.sidebar.selectbox( |
| "Selecciona el modelo:", |
| ["gpt-3.5-turbo", "gpt-4"], |
| index=0 |
| ) |
| st.sidebar.subheader("Ajustes del Modelo") |
| st.session_state['temperatura'] = st.sidebar.slider( |
| "Temperatura", |
| min_value=0.0, max_value=1.0, |
| value=st.session_state['temperatura'], |
| step=0.1 |
| ) |
| st.sidebar.text_input("Assistant ID", key="assistant_id", help="Introduce el Assistant ID del playground de OpenAI") |
|
|
| |
| def manejar_pregunta_usuario(pregunta_usuario): |
| st.session_state['mensajes_chat'].append({"role": "user", "content": pregunta_usuario}) |
| with st.chat_message("user"): |
| st.markdown(pregunta_usuario) |
| |
| |
| respuesta = f"Esta es una respuesta simulada. Aqu铆 hay un extracto del PDF:\n\n{st.session_state['pdf_texto'][:500]}" |
| |
| st.session_state['mensajes_chat'].append({"role": "assistant", "content": respuesta}) |
| with st.chat_message("assistant"): |
| st.markdown(respuesta) |
|
|
| |
| st.markdown( |
| """ |
| <style> |
| #video-container { |
| position: relative; |
| width: 100%; |
| height: 90vh; |
| overflow: hidden; |
| } |
| #background-video { |
| position: absolute; |
| top: 0; |
| left: 0; |
| width: 100%; |
| height: 100%; |
| object-fit: cover; |
| z-index: -1; |
| } |
| #chat-container { |
| position: absolute; |
| top: 0; |
| left: 0; |
| width: 100%; |
| height: 100%; |
| display: flex; |
| flex-direction: column; |
| justify-content: flex-end; |
| padding: 20px; |
| box-sizing: border-box; |
| } |
| .chat-message { |
| background: rgba(255, 255, 255, 0.8); |
| border-radius: 10px; |
| padding: 10px; |
| margin-bottom: 10px; |
| max-width: 70%; |
| } |
| .chat-message.user { |
| align-self: flex-start; |
| } |
| .chat-message.assistant { |
| align-self: flex-end; |
| background: rgba(0, 123, 255, 0.8); |
| color: white; |
| } |
| </style> |
| <div id="video-container"> |
| <video id="background-video" autoplay loop muted> |
| <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"> |
| </video> |
| <div id="chat-container"> |
| """, |
| unsafe_allow_html=True |
| ) |
|
|
| |
| for mensaje in st.session_state['mensajes_chat']: |
| clase = "user" if mensaje["role"] == "user" else "assistant" |
| st.markdown(f'<div class="chat-message {clase}">{mensaje["content"]}</div>', unsafe_allow_html=True) |
|
|
| |
| pregunta_usuario = st.text_input("Escribe tu pregunta aqu铆:", key='unique_chat_input_key', value=st.session_state['transcripcion_voz']) |
| if st.button("Enviar Pregunta"): |
| manejar_pregunta_usuario(pregunta_usuario) |
|
|
| st.markdown("</div></div>", unsafe_allow_html=True) |
|
|
| |
| st.image("/mnt/data/clara asesora.jpg", use_column_width=True) |
|
|