AIdeaText commited on
Commit
16dcc0e
1 Parent(s): c0c171a

Update modules/ui.py

Browse files
Files changed (1) hide show
  1. modules/ui.py +13 -4
modules/ui.py CHANGED
@@ -399,16 +399,19 @@ def display_chatbot_interface(lang_code):
399
  'title': "AIdeaText - Chatbot Multilingüe",
400
  'input_placeholder': "Escribe tu mensaje aquí...",
401
  'send_button': "Enviar",
 
402
  },
403
  'en': {
404
  'title': "AIdeaText - Multilingual Chatbot",
405
  'input_placeholder': "Type your message here...",
406
  'send_button': "Send",
 
407
  },
408
  'fr': {
409
  'title': "AIdeaText - Chatbot Multilingue",
410
  'input_placeholder': "Écrivez votre message ici...",
411
  'send_button': "Envoyer",
 
412
  }
413
  }
414
 
@@ -420,21 +423,27 @@ def display_chatbot_interface(lang_code):
420
  st.session_state.chatbot = initialize_chatbot()
421
 
422
  if 'messages' not in st.session_state:
423
- st.session_state.messages = []
424
 
 
425
  for message in st.session_state.messages:
426
  with st.chat_message(message["role"]):
427
  st.markdown(message["content"])
428
 
 
429
  if prompt := st.chat_input(t['input_placeholder']):
430
  st.session_state.messages.append({"role": "user", "content": prompt})
431
  with st.chat_message("user"):
432
  st.markdown(prompt)
433
 
434
  with st.chat_message("assistant"):
435
- response = get_chatbot_response(st.session_state.chatbot, prompt, lang_code)
436
- st.markdown(response)
437
- st.session_state.messages.append({"role": "assistant", "content": response})
 
 
 
 
438
 
439
  # Guardar la conversación en la base de datos
440
  store_chat_history(st.session_state.username, st.session_state.messages)
 
399
  'title': "AIdeaText - Chatbot Multilingüe",
400
  'input_placeholder': "Escribe tu mensaje aquí...",
401
  'send_button': "Enviar",
402
+ 'initial_message': "¡Hola! ¿En qué puedo ayudarte hoy?"
403
  },
404
  'en': {
405
  'title': "AIdeaText - Multilingual Chatbot",
406
  'input_placeholder': "Type your message here...",
407
  'send_button': "Send",
408
+ 'initial_message': "Hello! How can I assist you today?"
409
  },
410
  'fr': {
411
  'title': "AIdeaText - Chatbot Multilingue",
412
  'input_placeholder': "Écrivez votre message ici...",
413
  'send_button': "Envoyer",
414
+ 'initial_message': "Bonjour! Comment puis-je vous aider aujourd'hui?"
415
  }
416
  }
417
 
 
423
  st.session_state.chatbot = initialize_chatbot()
424
 
425
  if 'messages' not in st.session_state:
426
+ st.session_state.messages = [{"role": "assistant", "content": t['initial_message']}]
427
 
428
+ # Mostrar mensajes previos
429
  for message in st.session_state.messages:
430
  with st.chat_message(message["role"]):
431
  st.markdown(message["content"])
432
 
433
+ # Input del usuario
434
  if prompt := st.chat_input(t['input_placeholder']):
435
  st.session_state.messages.append({"role": "user", "content": prompt})
436
  with st.chat_message("user"):
437
  st.markdown(prompt)
438
 
439
  with st.chat_message("assistant"):
440
+ message_placeholder = st.empty()
441
+ full_response = ""
442
+ for response in get_chatbot_response(st.session_state.chatbot, prompt, lang_code):
443
+ full_response += response + " "
444
+ message_placeholder.markdown(full_response + "▌")
445
+ message_placeholder.markdown(full_response)
446
+ st.session_state.messages.append({"role": "assistant", "content": full_response})
447
 
448
  # Guardar la conversación en la base de datos
449
  store_chat_history(st.session_state.username, st.session_state.messages)