JeCabrera commited on
Commit
d99c92d
·
verified ·
1 Parent(s): 6d8e638

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -23
app.py CHANGED
@@ -222,12 +222,11 @@ if prompt := st.chat_input('¿En qué puedo ayudarte hoy?'):
222
 
223
  # Si es el primer mensaje, mostrar el mensaje de bienvenida
224
  if is_first_message:
225
- with st.chat_message(name=MODEL_ROLE, avatar=AI_AVATAR_ICON):
226
- st.markdown(WELCOME_MESSAGE)
227
 
228
  st.session_state.messages.append({
229
  'role': MODEL_ROLE,
230
- 'content': WELCOME_MESSAGE,
231
  'avatar': AI_AVATAR_ICON,
232
  })
233
 
@@ -244,30 +243,18 @@ if prompt := st.chat_input('¿En qué puedo ayudarte hoy?'):
244
  # Enviar mensaje al modelo
245
  response = st.session_state.chat.send_message(prompt, stream=True)
246
 
247
- # Mostrar respuesta del asistente
248
- with st.chat_message(name=MODEL_ROLE, avatar=AI_AVATAR_ICON):
249
- message_placeholder = st.empty()
250
- full_response = ''
251
-
252
- # Indicador de escritura
253
- typing_indicator = st.empty()
254
- typing_indicator.markdown("*Estoy analizando tu información...*")
255
-
256
- # Mostrar respuesta por fragmentos
257
- for chunk in response:
258
- for ch in chunk.text.split(' '):
259
- full_response += ch + ' '
260
- time.sleep(0.1)
261
- message_placeholder.write(full_response + '▌')
262
-
263
- # Eliminar indicador y mostrar respuesta completa
264
- typing_indicator.empty()
265
- message_placeholder.write(full_response)
266
 
267
  # Añadir respuesta al historial
268
  st.session_state.messages.append({
269
  'role': MODEL_ROLE,
270
- 'content': st.session_state.chat.history[-1].parts[0].text,
271
  'avatar': AI_AVATAR_ICON,
272
  })
273
 
 
222
 
223
  # Si es el primer mensaje, mostrar el mensaje de bienvenida
224
  if is_first_message:
225
+ mensaje_mostrado = mostrar_con_efecto_escritura(WELCOME_MESSAGE, velocidad=0.05)
 
226
 
227
  st.session_state.messages.append({
228
  'role': MODEL_ROLE,
229
+ 'content': mensaje_mostrado,
230
  'avatar': AI_AVATAR_ICON,
231
  })
232
 
 
243
  # Enviar mensaje al modelo
244
  response = st.session_state.chat.send_message(prompt, stream=True)
245
 
246
+ # Procesar la respuesta completa
247
+ full_text = ""
248
+ for chunk in response:
249
+ full_text += chunk.text
250
+
251
+ # Mostrar respuesta del asistente con efecto de escritura
252
+ mensaje_mostrado = mostrar_con_efecto_escritura(full_text)
 
 
 
 
 
 
 
 
 
 
 
 
253
 
254
  # Añadir respuesta al historial
255
  st.session_state.messages.append({
256
  'role': MODEL_ROLE,
257
+ 'content': mensaje_mostrado,
258
  'avatar': AI_AVATAR_ICON,
259
  })
260