JeCabrera commited on
Commit
d63457f
·
verified ·
1 Parent(s): af32d41

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -4
app.py CHANGED
@@ -434,11 +434,55 @@ def handle_example_click(prompt_text):
434
  st.session_state.show_examples = False
435
  st.session_state.messages = []
436
  st.session_state.current_chat_id = str(time.time())
437
- st.session_state.temp_prompt = prompt_text
438
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
 
440
- # Mostrar ejemplos solo si show_examples es True
441
- if st.session_state.show_examples:
442
  st.title("💡 RoboCopy - Asistente de PUVs")
443
  st.markdown("### Tu experto en crear Propuestas Únicas de Valor que convierten")
444
 
 
434
  st.session_state.show_examples = False
435
  st.session_state.messages = []
436
  st.session_state.current_chat_id = str(time.time())
437
+
438
+ # Mostrar mensaje del usuario
439
+ with st.chat_message('user', avatar=USER_AVATAR_ICON):
440
+ st.markdown(prompt_text)
441
+
442
+ # Añadir mensaje del usuario al historial
443
+ st.session_state.messages.append({
444
+ 'role': 'user',
445
+ 'content': prompt_text,
446
+ 'avatar': USER_AVATAR_ICON
447
+ })
448
+
449
+ # Asegurarnos de que el chat existe en memoria
450
+ if st.session_state.current_chat_id not in st.session_state.chats_in_memory:
451
+ st.session_state.chats_in_memory[st.session_state.current_chat_id] = {
452
+ 'messages': st.session_state.messages,
453
+ 'gemini_history': st.session_state.gemini_history,
454
+ 'title': 'Nuevo Chat'
455
+ }
456
+
457
+ # Procesar la respuesta del modelo directamente
458
+ try:
459
+ response = st.session_state.chat.send_message(prompt_text, stream=True)
460
+ full_text = ""
461
+ for chunk in response:
462
+ full_text += chunk.text
463
+
464
+ # Mostrar respuesta del asistente
465
+ mensaje_mostrado = mostrar_con_efecto_escritura(full_text, velocidad=0.05)
466
+
467
+ # Actualizar historial
468
+ st.session_state.messages.append({
469
+ 'role': MODEL_ROLE,
470
+ 'content': mensaje_mostrado,
471
+ 'avatar': AI_AVATAR_ICON,
472
+ })
473
+ st.session_state.gemini_history = st.session_state.chat.history
474
+
475
+ # Actualizar chat en memoria
476
+ st.session_state.chats_in_memory[st.session_state.current_chat_id].update({
477
+ 'messages': st.session_state.messages,
478
+ 'gemini_history': st.session_state.gemini_history,
479
+ 'title': st.session_state.chat_title
480
+ })
481
+ except Exception as e:
482
+ st.error(f"Error al procesar la solicitud: {str(e)}")
483
 
484
+ # Mostrar ejemplos solo si show_examples es True y no hay mensajes previos
485
+ if st.session_state.show_examples and not st.session_state.messages:
486
  st.title("💡 RoboCopy - Asistente de PUVs")
487
  st.markdown("### Tu experto en crear Propuestas Únicas de Valor que convierten")
488