Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
@@ -262,10 +262,9 @@ if not st.session_state.gemini_history:
|
|
262 |
st.session_state.gemini_history = st.session_state.chat.history
|
263 |
|
264 |
# === MOSTRAR MENSAJES DEL HISTORIAL ===
|
265 |
-
|
266 |
-
chat_input_container = st.container()
|
267 |
|
268 |
-
with
|
269 |
# === SECCIÓN DE EJEMPLOS ===
|
270 |
if st.session_state.show_examples and not st.session_state.messages:
|
271 |
st.title("💡 RoboCopy - Asistente de PUVs")
|
@@ -295,54 +294,29 @@ chat_input_container = st.container()
|
|
295 |
|
296 |
# Mostrar mensajes existentes
|
297 |
for message in st.session_state.messages:
|
298 |
-
with st.chat_message(
|
|
|
|
|
|
|
299 |
st.markdown(message['content'])
|
300 |
-
|
301 |
-
# Procesar entrada del usuario si existe
|
302 |
-
if 'user_input' in st.session_state:
|
303 |
-
prompt = st.session_state.user_input
|
304 |
-
del st.session_state.user_input
|
305 |
-
|
306 |
-
with st.chat_message("user", avatar=USER_AVATAR_ICON):
|
307 |
-
st.markdown(prompt)
|
308 |
-
add_message("user", prompt, USER_AVATAR_ICON)
|
309 |
-
|
310 |
-
# Actualizar título antes de procesar
|
311 |
-
try:
|
312 |
-
title_response = st.session_state.model.generate_content(
|
313 |
-
f"Título para consulta: '{prompt}' (máximo 4 palabras)"
|
314 |
-
)
|
315 |
-
st.session_state.chat_title = title_response.text.strip()[:25]
|
316 |
-
except Exception as e:
|
317 |
-
st.session_state.chat_title = f"Ejemplo-{time.strftime('%H:%M')}"
|
318 |
-
|
319 |
-
st.session_state.chats_in_memory[st.session_state.current_chat_id] = {
|
320 |
-
'messages': st.session_state.messages,
|
321 |
-
'gemini_history': st.session_state.gemini_history,
|
322 |
-
'title': st.session_state.chat_title
|
323 |
-
}
|
324 |
|
325 |
-
# Procesar
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
with chat_input_container:
|
331 |
-
new_prompt = st.chat_input('¿En qué puedo ayudarte hoy?')
|
332 |
-
if new_prompt:
|
333 |
-
# Simular el envío del mensaje
|
334 |
with st.chat_message("user", avatar=USER_AVATAR_ICON):
|
335 |
-
st.markdown(
|
336 |
-
add_message("user",
|
337 |
|
338 |
# Actualizar título antes de procesar
|
339 |
try:
|
340 |
title_response = st.session_state.model.generate_content(
|
341 |
-
f"Título para consulta: '{
|
342 |
)
|
343 |
st.session_state.chat_title = title_response.text.strip()[:25]
|
344 |
except Exception as e:
|
345 |
-
st.session_state.chat_title = f"
|
346 |
|
347 |
st.session_state.chats_in_memory[st.session_state.current_chat_id] = {
|
348 |
'messages': st.session_state.messages,
|
@@ -351,5 +325,31 @@ with chat_input_container:
|
|
351 |
}
|
352 |
|
353 |
# Procesar la respuesta una sola vez
|
354 |
-
process_model_response(
|
355 |
-
update_chat_memory()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
st.session_state.gemini_history = st.session_state.chat.history
|
263 |
|
264 |
# === MOSTRAR MENSAJES DEL HISTORIAL ===
|
265 |
+
chat_container = st.container()
|
|
|
266 |
|
267 |
+
with chat_container:
|
268 |
# === SECCIÓN DE EJEMPLOS ===
|
269 |
if st.session_state.show_examples and not st.session_state.messages:
|
270 |
st.title("💡 RoboCopy - Asistente de PUVs")
|
|
|
294 |
|
295 |
# Mostrar mensajes existentes
|
296 |
for message in st.session_state.messages:
|
297 |
+
with st.chat_message(
|
298 |
+
name=message['role'],
|
299 |
+
avatar=AI_AVATAR_ICON if message['role'] == MODEL_ROLE else USER_AVATAR_ICON
|
300 |
+
):
|
301 |
st.markdown(message['content'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
|
303 |
+
# Procesar entrada del usuario si existe
|
304 |
+
if 'user_input' in st.session_state:
|
305 |
+
prompt = st.session_state.user_input
|
306 |
+
del st.session_state.user_input
|
307 |
+
|
|
|
|
|
|
|
|
|
308 |
with st.chat_message("user", avatar=USER_AVATAR_ICON):
|
309 |
+
st.markdown(prompt)
|
310 |
+
add_message("user", prompt, USER_AVATAR_ICON)
|
311 |
|
312 |
# Actualizar título antes de procesar
|
313 |
try:
|
314 |
title_response = st.session_state.model.generate_content(
|
315 |
+
f"Título para consulta: '{prompt}' (máximo 4 palabras)"
|
316 |
)
|
317 |
st.session_state.chat_title = title_response.text.strip()[:25]
|
318 |
except Exception as e:
|
319 |
+
st.session_state.chat_title = f"Ejemplo-{time.strftime('%H:%M')}"
|
320 |
|
321 |
st.session_state.chats_in_memory[st.session_state.current_chat_id] = {
|
322 |
'messages': st.session_state.messages,
|
|
|
325 |
}
|
326 |
|
327 |
# Procesar la respuesta una sola vez
|
328 |
+
process_model_response(prompt)
|
329 |
+
update_chat_memory()
|
330 |
+
|
331 |
+
# Chat input al final del contenedor
|
332 |
+
new_prompt = st.chat_input('¿En qué puedo ayudarte hoy?')
|
333 |
+
if new_prompt:
|
334 |
+
with st.chat_message("user", avatar=USER_AVATAR_ICON):
|
335 |
+
st.markdown(new_prompt)
|
336 |
+
add_message("user", new_prompt, USER_AVATAR_ICON)
|
337 |
+
|
338 |
+
# Actualizar título antes de procesar
|
339 |
+
try:
|
340 |
+
title_response = st.session_state.model.generate_content(
|
341 |
+
f"Título para consulta: '{new_prompt}' (máximo 4 palabras)"
|
342 |
+
)
|
343 |
+
st.session_state.chat_title = title_response.text.strip()[:25]
|
344 |
+
except Exception as e:
|
345 |
+
st.session_state.chat_title = f"Chat-{time.strftime('%H:%M')}"
|
346 |
+
|
347 |
+
st.session_state.chats_in_memory[st.session_state.current_chat_id] = {
|
348 |
+
'messages': st.session_state.messages,
|
349 |
+
'gemini_history': st.session_state.gemini_history,
|
350 |
+
'title': st.session_state.chat_title
|
351 |
+
}
|
352 |
+
|
353 |
+
# Procesar la respuesta una sola vez
|
354 |
+
process_model_response(new_prompt)
|
355 |
+
update_chat_memory()
|