Spaces:
Runtime error
Runtime error
Upload 12 files
Browse files
app.py
CHANGED
@@ -66,41 +66,55 @@ def process_message(prompt, is_example=False):
|
|
66 |
|
67 |
with st.chat_message(MODEL_ROLE, avatar=AI_AVATAR_ICON):
|
68 |
try:
|
69 |
-
#
|
|
|
|
|
|
|
|
|
|
|
70 |
response = state.chat.send_message(
|
71 |
enhanced_prompt,
|
72 |
-
stream=True,
|
73 |
-
generation_config={"temperature": 0.9}
|
74 |
)
|
75 |
|
76 |
-
message_placeholder = st.empty()
|
77 |
full_response = ''
|
78 |
|
79 |
-
#
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
89 |
|
90 |
-
#
|
91 |
typing_indicator.empty()
|
92 |
|
93 |
-
# Mostrar respuesta
|
94 |
-
message_placeholder.
|
95 |
|
96 |
-
#
|
97 |
state.add_message(
|
98 |
role=MODEL_ROLE,
|
99 |
-
content=
|
100 |
-
avatar=AI_AVATAR_ICON
|
101 |
)
|
102 |
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
# Guardar historial actualizado
|
106 |
state.save_chat_history()
|
|
|
66 |
|
67 |
with st.chat_message(MODEL_ROLE, avatar=AI_AVATAR_ICON):
|
68 |
try:
|
69 |
+
# Configurar el placeholder y el indicador de escritura
|
70 |
+
message_placeholder = st.empty()
|
71 |
+
typing_indicator = st.empty()
|
72 |
+
typing_indicator.markdown("*Generando respuesta...*")
|
73 |
+
|
74 |
+
# Asegurar que siempre usamos streaming
|
75 |
response = state.chat.send_message(
|
76 |
enhanced_prompt,
|
77 |
+
stream=True,
|
78 |
+
generation_config={"temperature": 0.9}
|
79 |
)
|
80 |
|
|
|
81 |
full_response = ''
|
82 |
|
83 |
+
# Mejorar el manejo del streaming
|
84 |
+
try:
|
85 |
+
for chunk in response:
|
86 |
+
if chunk.text: # Verificar que hay texto en el chunk
|
87 |
+
for ch in chunk.text:
|
88 |
+
full_response += ch
|
89 |
+
time.sleep(0.01)
|
90 |
+
# Mantener el indicador mientras se escribe
|
91 |
+
typing_indicator.markdown("*Generando respuesta...*")
|
92 |
+
message_placeholder.markdown(full_response + '▌')
|
93 |
+
except Exception as e:
|
94 |
+
st.error(f"Error en el streaming: {str(e)}")
|
95 |
+
return
|
96 |
|
97 |
+
# Limpiar el indicador de escritura al finalizar
|
98 |
typing_indicator.empty()
|
99 |
|
100 |
+
# Mostrar respuesta final
|
101 |
+
message_placeholder.markdown(full_response)
|
102 |
|
103 |
+
# Actualizar el historial
|
104 |
state.add_message(
|
105 |
role=MODEL_ROLE,
|
106 |
+
content=full_response,
|
107 |
+
avatar=AI_AVATAR_ICON
|
108 |
)
|
109 |
|
110 |
+
# Guardar el historial actualizado
|
111 |
+
state.save_chat_history()
|
112 |
+
|
113 |
+
except Exception as e:
|
114 |
+
st.error(f"Error: {str(e)}")
|
115 |
+
return
|
116 |
+
|
117 |
+
state.gemini_history = state.chat.history
|
118 |
|
119 |
# Guardar historial actualizado
|
120 |
state.save_chat_history()
|