JeCabrera commited on
Commit
9d4e2d1
·
verified ·
1 Parent(s): f0365d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -12
app.py CHANGED
@@ -199,7 +199,24 @@ with col2:
199
  if hasattr(st.session_state, 'product_service') and st.session_state.product_service:
200
  product_name = st.session_state.product_service
201
  else:
202
- product_name = "Producto/Servicio"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
  # Get the instruction using the formula
205
  instruction = create_offer_instruction(
@@ -283,23 +300,28 @@ with col2:
283
  lines = [line for line in lines if line.strip()]
284
  response_text = '\n\n'.join(lines)
285
 
286
- # Natural integration of product name in Oferta Dorada
287
  if hasattr(st.session_state, 'product_service') and st.session_state.product_service:
288
  product_name = st.session_state.product_service
289
 
290
  # Split the text into lines to process each part of the formula
291
  lines = response_text.split('\n')
292
 
293
- # Process the promise (usually in the first few lines)
294
- for i in range(min(5, len(lines))):
295
- # If this line contains the promise, make product name uppercase
296
- if any(keyword in lines[i].lower() for keyword in ["promesa", "promise"]):
297
- lines[i] = lines[i].replace(product_name, product_name.upper())
298
-
299
- # Process the third line (if it exists) to remove quotes around product name
300
- if len(lines) > 3:
301
- lines[2] = lines[2].replace(f'"{product_name}"', product_name)
302
- lines[2] = lines[2].replace(f"'{product_name}'", product_name)
 
 
 
 
 
303
 
304
  # Rejoin the lines
305
  response_text = '\n'.join(lines)
 
199
  if hasattr(st.session_state, 'product_service') and st.session_state.product_service:
200
  product_name = st.session_state.product_service
201
  else:
202
+ # Generar un nombre creativo en lugar de usar "Producto/Servicio"
203
+ try:
204
+ creative_name_prompt = f"""Crea un nombre creativo y atractivo para un producto o servicio
205
+ basado en estas habilidades: {st.session_state.skills if hasattr(st.session_state, 'skills') else 'profesional'}.
206
+ El público objetivo es: {avatar_description}.
207
+ Responde SOLO con el nombre, sin explicaciones ni comillas."""
208
+
209
+ creative_name_response = model.generate_content(
210
+ creative_name_prompt,
211
+ generation_config=genai.GenerationConfig(temperature=0.8, max_output_tokens=30)
212
+ )
213
+ product_name = creative_name_response.text.strip().replace('"', '').replace("'", "")
214
+
215
+ # Si el nombre generado está vacío o es demasiado largo, usar un valor predeterminado
216
+ if not product_name or len(product_name) > 50:
217
+ product_name = "Sistema Profesional"
218
+ except Exception:
219
+ product_name = "Sistema Profesional"
220
 
221
  # Get the instruction using the formula
222
  instruction = create_offer_instruction(
 
300
  lines = [line for line in lines if line.strip()]
301
  response_text = '\n\n'.join(lines)
302
 
303
+ # Natural integration of product name in the response
304
  if hasattr(st.session_state, 'product_service') and st.session_state.product_service:
305
  product_name = st.session_state.product_service
306
 
307
  # Split the text into lines to process each part of the formula
308
  lines = response_text.split('\n')
309
 
310
+ # Process each line for proper product name integration
311
+ for i in range(len(lines)):
312
+ # For the second line (usually the promise in ALL CAPS), make product name uppercase
313
+ if i == 1 and st.session_state.formula_type == "Oferta Dorada":
314
+ lines[i] = lines[i].upper()
315
+
316
+ # Remove quotes around product name in all lines
317
+ lines[i] = lines[i].replace(f'"{product_name}"', product_name)
318
+ lines[i] = lines[i].replace(f"'{product_name}'", product_name)
319
+
320
+ # Ensure product name is properly capitalized in benefit descriptions
321
+ if i >= 2 and "sistema" in lines[i].lower() and product_name.lower() not in lines[i].lower():
322
+ lines[i] = lines[i].replace("sistema", product_name, 1)
323
+ if i >= 2 and "método" in lines[i].lower() and product_name.lower() not in lines[i].lower():
324
+ lines[i] = lines[i].replace("método", product_name, 1)
325
 
326
  # Rejoin the lines
327
  response_text = '\n'.join(lines)