JeCabrera commited on
Commit
68f83d1
·
verified ·
1 Parent(s): ade11a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -2
app.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  from google import genai
5
  from google.genai import types
6
  import random
 
7
  from formulas import headline_formulas
8
  from angles import angles
9
 
@@ -20,6 +21,18 @@ if not api_key:
20
  client = genai.Client(api_key=api_key)
21
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  def build_headline_context(selected_formula_key, selected_angle, target_audience, product):
24
  selected_formula = headline_formulas[selected_formula_key]
25
 
@@ -65,6 +78,8 @@ def generate_headlines(number_of_headlines, target_audience, product, temperatur
65
  product=product
66
  )
67
 
 
 
68
  system_prompt = f"""Eres un copywriter de clase mundial especializado en escribir titulares, hooks y líneas de asunto que captan la atención rápidamente y despiertan una curiosidad genuina.
69
 
70
  OBJETIVO:
@@ -81,16 +96,24 @@ CALIDAD:
81
  - Prioriza beneficio concreto + especificidad.
82
  - Mantén tono natural para el público objetivo.
83
  - No copies ejemplos literalmente.
84
- - Evita repetir estructuras entre líneas."""
 
85
 
86
  headlines_instruction = (
87
  f"{system_prompt}\n\n"
88
  f"PÚBLICO: {target_audience}\n"
89
- f"PRODUCTO/SERVICIO: {product}\n"
90
  f"FÓRMULA: {selected_formula_key}\n"
91
  f"DESCRIPCIÓN CORTA DE LA FÓRMULA:\n{context['formula_description_short']}\n\n"
92
  )
93
 
 
 
 
 
 
 
 
94
  if selected_angle != "NINGUNO":
95
  headlines_instruction += (
96
  f"ÁNGULO: {selected_angle}\n"
@@ -104,6 +127,11 @@ CALIDAD:
104
  headlines_instruction += f"{i}. {example}\n"
105
  headlines_instruction += "\n"
106
 
 
 
 
 
 
107
  headlines_instruction += f"Genera ahora {number_of_headlines} titulares."
108
 
109
  response = client.models.generate_content(
 
4
  from google import genai
5
  from google.genai import types
6
  import random
7
+ import re
8
  from formulas import headline_formulas
9
  from angles import angles
10
 
 
21
  client = genai.Client(api_key=api_key)
22
 
23
 
24
+ SPANISH_STOPWORDS = {
25
+ "de", "del", "la", "el", "los", "las", "y", "o", "u", "a", "en", "con",
26
+ "para", "por", "sin", "un", "una", "unos", "unas", "al", "lo", "que", "tu", "tus"
27
+ }
28
+
29
+
30
+ def extract_product_keywords(product):
31
+ words = re.findall(r"[a-záéíóúñA-ZÁÉÍÓÚÑ0-9]+", product.lower())
32
+ keywords = [w for w in words if len(w) >= 4 and w not in SPANISH_STOPWORDS]
33
+ return list(dict.fromkeys(keywords))
34
+
35
+
36
  def build_headline_context(selected_formula_key, selected_angle, target_audience, product):
37
  selected_formula = headline_formulas[selected_formula_key]
38
 
 
78
  product=product
79
  )
80
 
81
+ product_keywords = extract_product_keywords(product)
82
+
83
  system_prompt = f"""Eres un copywriter de clase mundial especializado en escribir titulares, hooks y líneas de asunto que captan la atención rápidamente y despiertan una curiosidad genuina.
84
 
85
  OBJETIVO:
 
96
  - Prioriza beneficio concreto + especificidad.
97
  - Mantén tono natural para el público objetivo.
98
  - No copies ejemplos literalmente.
99
+ - Evita repetir estructuras entre líneas.
100
+ - No menciones explícitamente el producto o servicio en ningún titular."""
101
 
102
  headlines_instruction = (
103
  f"{system_prompt}\n\n"
104
  f"PÚBLICO: {target_audience}\n"
105
+ f"CONTEXTO INTERNO (NO MENCIONAR EN EL OUTPUT): {product}\n"
106
  f"FÓRMULA: {selected_formula_key}\n"
107
  f"DESCRIPCIÓN CORTA DE LA FÓRMULA:\n{context['formula_description_short']}\n\n"
108
  )
109
 
110
+ if product_keywords:
111
+ blocked_terms = ", ".join(product_keywords)
112
+ headlines_instruction += (
113
+ "PALABRAS PROHIBIDAS EN EL TITULAR (derivadas del producto): "
114
+ f"{blocked_terms}\n\n"
115
+ )
116
+
117
  if selected_angle != "NINGUNO":
118
  headlines_instruction += (
119
  f"ÁNGULO: {selected_angle}\n"
 
127
  headlines_instruction += f"{i}. {example}\n"
128
  headlines_instruction += "\n"
129
 
130
+ headlines_instruction += "GUÍA ADICIONAL:\n"
131
+ for guidance in context["extra_guidance"]:
132
+ headlines_instruction += f"- {guidance}\n"
133
+
134
+ headlines_instruction += "\n"
135
  headlines_instruction += f"Genera ahora {number_of_headlines} titulares."
136
 
137
  response = client.models.generate_content(