Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
@@ -293,12 +293,12 @@ with chat_container:
|
|
293 |
chat_input_container = st.container()
|
294 |
|
295 |
# Mostrar mensajes existentes
|
296 |
-
for message in st.session_state.messages:
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
|
303 |
# Procesar entrada del usuario si existe
|
304 |
if 'user_input' in st.session_state:
|
@@ -309,14 +309,14 @@ for message in st.session_state.messages:
|
|
309 |
st.markdown(prompt)
|
310 |
add_message("user", prompt, USER_AVATAR_ICON)
|
311 |
|
312 |
-
# Actualizar título
|
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"
|
320 |
|
321 |
st.session_state.chats_in_memory[st.session_state.current_chat_id] = {
|
322 |
'messages': st.session_state.messages,
|
@@ -324,32 +324,29 @@ for message in st.session_state.messages:
|
|
324 |
'title': st.session_state.chat_title
|
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 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
chat_input_container = st.container()
|
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:
|
|
|
309 |
st.markdown(prompt)
|
310 |
add_message("user", prompt, USER_AVATAR_ICON)
|
311 |
|
312 |
+
# Actualizar título y procesar respuesta
|
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"Chat-{time.strftime('%H:%M')}"
|
320 |
|
321 |
st.session_state.chats_in_memory[st.session_state.current_chat_id] = {
|
322 |
'messages': st.session_state.messages,
|
|
|
324 |
'title': st.session_state.chat_title
|
325 |
}
|
326 |
|
|
|
327 |
process_model_response(prompt)
|
328 |
update_chat_memory()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
|
330 |
+
# Chat input al final
|
331 |
+
new_prompt = st.chat_input('¿En qué puedo ayudarte hoy?')
|
332 |
+
if new_prompt:
|
333 |
+
with st.chat_message("user", avatar=USER_AVATAR_ICON):
|
334 |
+
st.markdown(new_prompt)
|
335 |
+
add_message("user", new_prompt, USER_AVATAR_ICON)
|
336 |
+
|
337 |
+
try:
|
338 |
+
title_response = st.session_state.model.generate_content(
|
339 |
+
f"Título para consulta: '{new_prompt}' (máximo 4 palabras)"
|
340 |
+
)
|
341 |
+
st.session_state.chat_title = title_response.text.strip()[:25]
|
342 |
+
except Exception as e:
|
343 |
+
st.session_state.chat_title = f"Chat-{time.strftime('%H:%M')}"
|
344 |
+
|
345 |
+
st.session_state.chats_in_memory[st.session_state.current_chat_id] = {
|
346 |
+
'messages': st.session_state.messages,
|
347 |
+
'gemini_history': st.session_state.gemini_history,
|
348 |
+
'title': st.session_state.chat_title
|
349 |
+
}
|
350 |
+
|
351 |
+
process_model_response(new_prompt)
|
352 |
+
update_chat_memory()
|