JeCabrera commited on
Commit
32296d6
verified
1 Parent(s): bdceaf0

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -70
app.py CHANGED
@@ -5,6 +5,13 @@ import streamlit as st
5
  import google.generativeai as genai
6
  from dotenv import load_dotenv
7
 
 
 
 
 
 
 
 
8
  # Funci贸n para cargar CSS personalizado
9
  def load_css(file_path):
10
  with open(file_path) as f:
@@ -417,13 +424,6 @@ if prompt := st.chat_input('驴En qu茅 puedo ayudarte hoy?'):
417
  # Salir del bucle si la solicitud fue exitosa
418
  break
419
 
420
- # Configuraci贸n inicial de la p谩gina
421
- st.set_page_config(
422
- page_title="RoboCopy - Creador de PUVs",
423
- page_icon="馃殌",
424
- layout="wide"
425
- )
426
-
427
  # T铆tulo y subt铆tulo principales
428
  st.title("馃挕 RoboCopy - Asistente de PUVs")
429
  st.markdown("### Tu experto en crear Propuestas 脷nicas de Valor que convierten")
@@ -464,66 +464,3 @@ with col2:
464
  # Separador visual
465
  st.markdown("---")
466
 
467
- # Implementaci贸n de reintentos con retroceso exponencial
468
- max_retries = 3
469
- retry_count = 0
470
- while retry_count < max_retries:
471
- try:
472
- # Enviar mensaje al modelo
473
- response = st.session_state.chat.send_message(prompt, stream=True)
474
-
475
- # Procesar la respuesta completa
476
- full_text = ""
477
- for chunk in response:
478
- full_text += chunk.text
479
-
480
- # Mostrar respuesta del asistente con efecto de escritura
481
- mensaje_mostrado = mostrar_con_efecto_escritura(full_text, velocidad=0.05)
482
-
483
- # A帽adir respuesta al historial
484
- st.session_state.messages.append({
485
- 'role': MODEL_ROLE,
486
- 'content': mensaje_mostrado,
487
- 'avatar': AI_AVATAR_ICON,
488
- })
489
-
490
- # Actualizar historial
491
- st.session_state.gemini_history = st.session_state.chat.history
492
-
493
- # Actualizar chat en memoria
494
- st.session_state.chats_in_memory[st.session_state.current_chat_id].update({
495
- 'messages': st.session_state.messages,
496
- 'gemini_history': st.session_state.gemini_history,
497
- 'title': st.session_state.chat_title
498
- })
499
-
500
- break
501
-
502
- except Exception as e:
503
- retry_count += 1
504
- if retry_count >= max_retries:
505
- error_message = f"Lo siento, estoy experimentando problemas para procesar tu solicitud. Por favor, intenta de nuevo m谩s tarde. Error: {str(e)}"
506
-
507
- with st.chat_message(name=MODEL_ROLE, avatar=AI_AVATAR_ICON):
508
- st.error(error_message)
509
-
510
- st.session_state.messages.append({
511
- 'role': MODEL_ROLE,
512
- 'content': error_message,
513
- 'avatar': AI_AVATAR_ICON,
514
- })
515
-
516
- # Actualizar chat en memoria con el error
517
- st.session_state.chats_in_memory[st.session_state.current_chat_id].update({
518
- 'messages': st.session_state.messages,
519
- 'gemini_history': st.session_state.gemini_history,
520
- 'title': st.session_state.chat_title
521
- })
522
- else:
523
- wait_time = (2 ** retry_count) + (time.time() % 1)
524
- time.sleep(wait_time)
525
-
526
- # Salir del bucle si la solicitud fue exitosa
527
- break
528
-
529
-
 
5
  import google.generativeai as genai
6
  from dotenv import load_dotenv
7
 
8
+ # Configuraci贸n inicial de la p谩gina (DEBE IR AL INICIO)
9
+ st.set_page_config(
10
+ page_title="RoboCopy - Creador de PUVs",
11
+ page_icon="馃殌",
12
+ layout="wide"
13
+ )
14
+
15
  # Funci贸n para cargar CSS personalizado
16
  def load_css(file_path):
17
  with open(file_path) as f:
 
424
  # Salir del bucle si la solicitud fue exitosa
425
  break
426
 
 
 
 
 
 
 
 
427
  # T铆tulo y subt铆tulo principales
428
  st.title("馃挕 RoboCopy - Asistente de PUVs")
429
  st.markdown("### Tu experto en crear Propuestas 脷nicas de Valor que convierten")
 
464
  # Separador visual
465
  st.markdown("---")
466