Spaces:
Runtime error
Runtime error
Update pages/galatea_asistente.py
Browse files- pages/galatea_asistente.py +17 -23
pages/galatea_asistente.py
CHANGED
|
@@ -12,7 +12,7 @@ st.set_page_config(page_title="Galatea Asistente", layout="wide")
|
|
| 12 |
# Funci贸n para inicializar el estado de la sesi贸n
|
| 13 |
def inicializar_estado():
|
| 14 |
if 'modelo' not in st.session_state:
|
| 15 |
-
st.session_state['modelo'] = "gpt-
|
| 16 |
if 'temperatura' not in st.session_state:
|
| 17 |
st.session_state['temperatura'] = 0.5
|
| 18 |
if 'mensajes_chat' not in st.session_state:
|
|
@@ -42,23 +42,22 @@ st.session_state['temperatura'] = st.sidebar.slider(
|
|
| 42 |
st.sidebar.text_input("Assistant ID", key="assistant_id", help="Introduce el Assistant ID del playground de OpenAI")
|
| 43 |
|
| 44 |
# Funci贸n para extraer texto de un PDF
|
| 45 |
-
def extraer_texto_pdf(
|
| 46 |
texto = ""
|
| 47 |
-
|
| 48 |
-
with
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
for page in range(len(reader.pages)):
|
| 55 |
-
texto += reader.pages[page].extract_text()
|
| 56 |
-
except Exception as e:
|
| 57 |
-
st.error(f"Error al extraer texto del PDF: {e}")
|
| 58 |
-
finally:
|
| 59 |
-
os.unlink(temp_file_path)
|
| 60 |
return texto
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# Funci贸n para manejar la pregunta del usuario
|
| 63 |
def manejar_pregunta_usuario(pregunta_usuario):
|
| 64 |
st.session_state['mensajes_chat'].append({"role": "user", "content": pregunta_usuario})
|
|
@@ -124,14 +123,17 @@ st.markdown(
|
|
| 124 |
padding: 10px;
|
| 125 |
margin-bottom: 10px;
|
| 126 |
max-width: 70%;
|
|
|
|
| 127 |
}
|
| 128 |
.chat-message.user {
|
| 129 |
align-self: flex-start;
|
|
|
|
| 130 |
}
|
| 131 |
.chat-message.assistant {
|
| 132 |
align-self: flex-end;
|
| 133 |
background: rgba(0, 123, 255, 0.8);
|
| 134 |
color: white;
|
|
|
|
| 135 |
}
|
| 136 |
</style>
|
| 137 |
<div id="video-container">
|
|
@@ -155,13 +157,5 @@ if st.button("Enviar Pregunta"):
|
|
| 155 |
|
| 156 |
st.markdown("</div></div>", unsafe_allow_html=True)
|
| 157 |
|
| 158 |
-
# Cargar y extraer texto del PDF
|
| 159 |
-
archivo_pdf = st.file_uploader("Cargar PDF", type='pdf')
|
| 160 |
-
if archivo_pdf is not None:
|
| 161 |
-
texto_pdf = extraer_texto_pdf(archivo_pdf)
|
| 162 |
-
st.session_state['texto_preprocesado_pdf'] = texto_pdf
|
| 163 |
-
st.success("Texto del PDF cargado y preprocesado con 茅xito.")
|
| 164 |
-
|
| 165 |
# Incluir imagen de fondo (opcional)
|
| 166 |
st.image("/mnt/data/clara asesora.jpg", use_column_width=True)
|
| 167 |
-
|
|
|
|
| 12 |
# Funci贸n para inicializar el estado de la sesi贸n
|
| 13 |
def inicializar_estado():
|
| 14 |
if 'modelo' not in st.session_state:
|
| 15 |
+
st.session_state['modelo'] = "gpt-4"
|
| 16 |
if 'temperatura' not in st.session_state:
|
| 17 |
st.session_state['temperatura'] = 0.5
|
| 18 |
if 'mensajes_chat' not in st.session_state:
|
|
|
|
| 42 |
st.sidebar.text_input("Assistant ID", key="assistant_id", help="Introduce el Assistant ID del playground de OpenAI")
|
| 43 |
|
| 44 |
# Funci贸n para extraer texto de un PDF
|
| 45 |
+
def extraer_texto_pdf(ruta_archivo):
|
| 46 |
texto = ""
|
| 47 |
+
try:
|
| 48 |
+
with open(ruta_archivo, 'rb') as file:
|
| 49 |
+
reader = PyPDF2.PdfReader(file)
|
| 50 |
+
for page in range(len(reader.pages)):
|
| 51 |
+
texto += reader.pages[page].extract_text()
|
| 52 |
+
except Exception as e:
|
| 53 |
+
st.error(f"Error al extraer texto del PDF: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
return texto
|
| 55 |
|
| 56 |
+
# Cargar y preprocesar el texto del PDF predefinido
|
| 57 |
+
ruta_pdf_predefinido = "instrucciones.pdf" # Actualiza esta ruta con la ruta real de tu archivo PDF
|
| 58 |
+
texto_pdf = extraer_texto_pdf(ruta_pdf_predefinido)
|
| 59 |
+
st.session_state['texto_preprocesado_pdf'] = texto_pdf
|
| 60 |
+
|
| 61 |
# Funci贸n para manejar la pregunta del usuario
|
| 62 |
def manejar_pregunta_usuario(pregunta_usuario):
|
| 63 |
st.session_state['mensajes_chat'].append({"role": "user", "content": pregunta_usuario})
|
|
|
|
| 123 |
padding: 10px;
|
| 124 |
margin-bottom: 10px;
|
| 125 |
max-width: 70%;
|
| 126 |
+
border: 2px solid #007BFF; /* Borde azul */
|
| 127 |
}
|
| 128 |
.chat-message.user {
|
| 129 |
align-self: flex-start;
|
| 130 |
+
border-color: #007BFF; /* Borde azul para usuario */
|
| 131 |
}
|
| 132 |
.chat-message.assistant {
|
| 133 |
align-self: flex-end;
|
| 134 |
background: rgba(0, 123, 255, 0.8);
|
| 135 |
color: white;
|
| 136 |
+
border-color: #0056b3; /* Borde azul oscuro para asistente */
|
| 137 |
}
|
| 138 |
</style>
|
| 139 |
<div id="video-container">
|
|
|
|
| 157 |
|
| 158 |
st.markdown("</div></div>", unsafe_allow_html=True)
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
# Incluir imagen de fondo (opcional)
|
| 161 |
st.image("/mnt/data/clara asesora.jpg", use_column_width=True)
|
|
|