Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -150,7 +150,8 @@ st.write('# Creador de Propuestas Únicas de Valor')
|
|
150 |
# Inicializar mensajes si es un chat nuevo
|
151 |
if not st.session_state.get('messages'):
|
152 |
st.session_state.messages = []
|
153 |
-
#
|
|
|
154 |
with st.chat_message(name=MODEL_ROLE, avatar=AI_AVATAR_ICON):
|
155 |
st.markdown(WELCOME_MESSAGE)
|
156 |
|
@@ -178,23 +179,29 @@ except:
|
|
178 |
st.session_state.gemini_history = []
|
179 |
print('new_cache made')
|
180 |
|
181 |
-
# Configuración del modelo
|
182 |
model = genai.GenerativeModel(
|
183 |
-
model_name='gemini-2.0-flash'
|
184 |
-
system_instruction=SYSTEM_PROMPT
|
185 |
)
|
186 |
st.session_state.model = model
|
187 |
st.session_state.chat = st.session_state.model.start_chat(
|
188 |
history=st.session_state.gemini_history,
|
189 |
)
|
190 |
|
191 |
-
#
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
# React to user input
|
200 |
if prompt := st.chat_input('¿Cuál es tu producto o servicio?'): # Mensaje más específico
|
|
|
150 |
# Inicializar mensajes si es un chat nuevo
|
151 |
if not st.session_state.get('messages'):
|
152 |
st.session_state.messages = []
|
153 |
+
# Eliminamos el mensaje automático de bienvenida
|
154 |
+
# No añadimos ningún mensaje inicial
|
155 |
with st.chat_message(name=MODEL_ROLE, avatar=AI_AVATAR_ICON):
|
156 |
st.markdown(WELCOME_MESSAGE)
|
157 |
|
|
|
179 |
st.session_state.gemini_history = []
|
180 |
print('new_cache made')
|
181 |
|
182 |
+
# Configuración del modelo sin el parámetro system_instruction
|
183 |
model = genai.GenerativeModel(
|
184 |
+
model_name='gemini-2.0-flash'
|
|
|
185 |
)
|
186 |
st.session_state.model = model
|
187 |
st.session_state.chat = st.session_state.model.start_chat(
|
188 |
history=st.session_state.gemini_history,
|
189 |
)
|
190 |
|
191 |
+
# Si es un chat nuevo, enviar el prompt del sistema como primer mensaje
|
192 |
+
if not st.session_state.gemini_history:
|
193 |
+
# Enviamos el prompt del sistema como primer mensaje (invisible para el usuario)
|
194 |
+
st.session_state.chat.send_message(SYSTEM_PROMPT)
|
195 |
+
# No guardamos este mensaje en st.session_state.messages para que no se muestre al usuario
|
196 |
+
# pero sí en gemini_history para que el modelo lo recuerde
|
197 |
+
st.session_state.gemini_history = st.session_state.chat.history
|
198 |
+
# Display chat messages from history on app rerun
|
199 |
+
for message in st.session_state.messages:
|
200 |
+
with st.chat_message(
|
201 |
+
name=message['role'],
|
202 |
+
avatar=message.get('avatar'),
|
203 |
+
):
|
204 |
+
st.markdown(message['content'])
|
205 |
|
206 |
# React to user input
|
207 |
if prompt := st.chat_input('¿Cuál es tu producto o servicio?'): # Mensaje más específico
|