Spaces:
Sleeping
Sleeping
Upload 17 files
Browse files- app.py +79 -32
- formulas.py +21 -1
app.py
CHANGED
@@ -4,7 +4,7 @@ import os
|
|
4 |
import time
|
5 |
from dotenv import load_dotenv
|
6 |
from styles import get_custom_css, get_response_html_wrapper
|
7 |
-
from formulas import offer_formulas
|
8 |
import PyPDF2
|
9 |
import docx
|
10 |
from PIL import Image
|
@@ -270,42 +270,89 @@ with col2:
|
|
270 |
# Get the response text
|
271 |
response_text = response.text
|
272 |
|
273 |
-
#
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
response_text = '\n\n'.join(lines)
|
|
|
|
|
283 |
|
284 |
-
#
|
285 |
-
if
|
286 |
-
|
|
|
287 |
|
288 |
-
#
|
289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
|
291 |
-
#
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
|
|
|
|
|
|
|
|
|
|
300 |
|
301 |
-
#
|
302 |
-
if
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
# Rejoin the lines
|
308 |
-
response_text = '\n'.join(lines)
|
309 |
|
310 |
st.session_state.offer_result = response_text
|
311 |
st.session_state.generated = True # Mark as generated
|
|
|
4 |
import time
|
5 |
from dotenv import load_dotenv
|
6 |
from styles import get_custom_css, get_response_html_wrapper
|
7 |
+
from formulas import offer_formulas, formula_formatting
|
8 |
import PyPDF2
|
9 |
import docx
|
10 |
from PIL import Image
|
|
|
270 |
# Get the response text
|
271 |
response_text = response.text
|
272 |
|
273 |
+
# Apply formatting to all formulas - MOVED OUTSIDE THE CONDITION
|
274 |
+
# Obtener la configuración de formato para la fórmula actual
|
275 |
+
current_formula = st.session_state.formula_type
|
276 |
+
format_config = formula_formatting.get(current_formula, {
|
277 |
+
"uppercase_lines": [],
|
278 |
+
"spacing": "single",
|
279 |
+
"product_integration": False,
|
280 |
+
"replace_terms": []
|
281 |
+
})
|
282 |
+
|
283 |
+
# Aplicar formato según la configuración
|
284 |
+
lines = response_text.split('\n')
|
285 |
+
lines = [line.lstrip() for line in lines] # Elimina espacios al inicio de cada línea
|
286 |
+
|
287 |
+
# Aplicar mayúsculas a líneas específicas
|
288 |
+
for line_index in format_config["uppercase_lines"]:
|
289 |
+
if line_index < len(lines):
|
290 |
+
lines[line_index] = lines[line_index].upper()
|
291 |
+
|
292 |
+
# Eliminar líneas en blanco extras
|
293 |
+
lines = [line for line in lines if line.strip()]
|
294 |
+
|
295 |
+
# Aplicar espaciado
|
296 |
+
if format_config["spacing"] == "double":
|
297 |
response_text = '\n\n'.join(lines)
|
298 |
+
else:
|
299 |
+
response_text = '\n'.join(lines)
|
300 |
|
301 |
+
# Integrar nombre del producto si está configurado
|
302 |
+
if format_config["product_integration"]:
|
303 |
+
# Verificar si el usuario proporcionó un nombre de producto
|
304 |
+
has_product_name = hasattr(st.session_state, 'product_service') and st.session_state.product_service
|
305 |
|
306 |
+
# Si no hay nombre de producto pero el nivel de sofisticación es 3 o mayor, generar uno genérico
|
307 |
+
if not has_product_name and hasattr(st.session_state, 'sophistication_level'):
|
308 |
+
sophistication_level = st.session_state.sophistication_level
|
309 |
+
if sophistication_level and sophistication_level.startswith(('nivel_3', 'nivel_4', 'nivel_5')):
|
310 |
+
# Generar un nombre genérico basado en la industria o tema
|
311 |
+
industry = st.session_state.get('industry', '')
|
312 |
+
if industry:
|
313 |
+
if 'marketing' in industry.lower():
|
314 |
+
product_service_value = "Sistema de Marketing Estratégico"
|
315 |
+
elif 'finanzas' in industry.lower() or 'inversión' in industry.lower():
|
316 |
+
product_service_value = "Método de Inversión Inteligente"
|
317 |
+
elif 'salud' in industry.lower() or 'bienestar' in industry.lower():
|
318 |
+
product_service_value = "Programa de Transformación Integral"
|
319 |
+
elif 'productividad' in industry.lower():
|
320 |
+
product_service_value = "Sistema de Productividad Avanzada"
|
321 |
+
else:
|
322 |
+
product_service_value = "Sistema Transformador"
|
323 |
+
else:
|
324 |
+
product_service_value = "Sistema Transformador"
|
325 |
+
|
326 |
+
# Guardar el nombre generado para uso futuro
|
327 |
+
st.session_state.generated_product_name = product_service_value
|
328 |
+
else:
|
329 |
+
# Para niveles 1-2, no hacemos nada especial
|
330 |
+
# Simplemente usamos los términos genéricos que ya están en el texto
|
331 |
+
product_service_value = None
|
332 |
+
else:
|
333 |
+
# Usar el nombre proporcionado por el usuario
|
334 |
+
product_service_value = st.session_state.product_service if has_product_name else None
|
335 |
|
336 |
+
# Procesar cada línea si tenemos un nombre de producto
|
337 |
+
# Solo hacemos reemplazos si hay un nombre de producto Y no estamos en nivel 1-2
|
338 |
+
# O si el usuario proporcionó explícitamente un nombre
|
339 |
+
if product_service_value:
|
340 |
+
lines = response_text.split('\n')
|
341 |
+
for i in range(len(lines)):
|
342 |
+
# Eliminar comillas alrededor del nombre del producto
|
343 |
+
lines[i] = lines[i].replace(f'"{product_service_value}"', product_service_value)
|
344 |
+
lines[i] = lines[i].replace(f"'{product_service_value}'", product_service_value)
|
345 |
+
|
346 |
+
# Reemplazar términos genéricos con el nombre del producto
|
347 |
+
for term in format_config["replace_terms"]:
|
348 |
+
if term.lower() in lines[i].lower() and product_service_value.lower() not in lines[i].lower():
|
349 |
+
lines[i] = lines[i].replace(term, product_service_value, 1)
|
350 |
|
351 |
+
# Rejuntar las líneas con el espaciado adecuado
|
352 |
+
if format_config["spacing"] == "double":
|
353 |
+
response_text = '\n\n'.join(lines)
|
354 |
+
else:
|
355 |
+
response_text = '\n'.join(lines)
|
|
|
|
|
|
|
356 |
|
357 |
st.session_state.offer_result = response_text
|
358 |
st.session_state.generated = True # Mark as generated
|
formulas.py
CHANGED
@@ -555,7 +555,27 @@ SPECIFIC INSTRUCTIONS FOR THE UNIQUE VALUE PROPOSITION:
|
|
555 |
}
|
556 |
}
|
557 |
|
558 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
559 |
|
560 |
def evaluate_contraste_revelador(situacion, solucion, resultado):
|
561 |
"""Evalúa la calidad de una fórmula de Contraste Revelador"""
|
|
|
555 |
}
|
556 |
}
|
557 |
|
558 |
+
# Add this if it's not already there
|
559 |
+
formula_formatting = {
|
560 |
+
"Oferta Dorada": {
|
561 |
+
"uppercase_lines": [1], # The second line (index 1) should be in uppercase
|
562 |
+
"spacing": "double", # Double spacing between lines
|
563 |
+
"product_integration": True, # Replace generic terms with product name
|
564 |
+
"replace_terms": ["sistema", "método", "programa", "solución"] # Terms to replace
|
565 |
+
},
|
566 |
+
"Contraste Revelador": {
|
567 |
+
"uppercase_lines": [1], # The solution line should be in uppercase
|
568 |
+
"spacing": "double", # Double spacing between lines
|
569 |
+
"product_integration": True, # Replace generic terms with product name
|
570 |
+
"replace_terms": ["sistema", "método", "programa", "solución"] # Terms to replace
|
571 |
+
},
|
572 |
+
"Propuesta Única de Valor": {
|
573 |
+
"uppercase_lines": [1], # The value proposition line should be in uppercase
|
574 |
+
"spacing": "double", # Double spacing between lines
|
575 |
+
"product_integration": True, # Replace generic terms with product name
|
576 |
+
"replace_terms": ["sistema", "método", "programa", "solución"] # Terms to replace
|
577 |
+
}
|
578 |
+
}
|
579 |
|
580 |
def evaluate_contraste_revelador(situacion, solucion, resultado):
|
581 |
"""Evalúa la calidad de una fórmula de Contraste Revelador"""
|