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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -117
app.py CHANGED
@@ -24,11 +24,12 @@ def build_headline_context(selected_formula_key, selected_angle, target_audience
24
  selected_formula = headline_formulas[selected_formula_key]
25
 
26
  formula_description = selected_formula.get("description", "").strip()
 
27
  formula_examples = selected_formula.get("examples", [])
28
 
29
  random_examples = random.sample(
30
  formula_examples,
31
- min(5, len(formula_examples))
32
  ) if formula_examples else []
33
 
34
  angle_instruction = ""
@@ -36,13 +37,23 @@ def build_headline_context(selected_formula_key, selected_angle, target_audience
36
 
37
  if selected_angle != "NINGUNO" and selected_angle in angles:
38
  angle_instruction = angles[selected_angle].get("instruction", "").strip()
39
- angle_examples = angles[selected_angle].get("examples", [])[:3]
 
 
 
 
 
 
 
 
40
 
41
  return {
42
  "formula_description": formula_description,
 
43
  "formula_examples": random_examples,
44
  "angle_instruction": angle_instruction,
45
- "angle_examples": angle_examples
 
46
  }
47
 
48
 
@@ -54,132 +65,57 @@ def generate_headlines(number_of_headlines, target_audience, product, temperatur
54
  product=product
55
  )
56
 
57
- system_prompt = """You are a world-class copywriter specialized in writing headlines, hooks, and subject lines that capture attention quickly and spark genuine curiosity.
58
-
59
- FORMAT RULES:
60
- - Each headline must start with a number and period
61
- - Write one headline per line
62
- - Do not add explanations or categories
63
- - Avoid unnecessary symbols
64
- - Each headline must feel complete, intriguing, and natural
65
-
66
- CORE RULES:
67
- - Each headline must be unique
68
- - Avoid clichés and generic language
69
- - Keep the tone intriguing but credible
70
- - Use language that feels natural for the target audience
71
- - Focus on clear and desirable outcomes
72
-
73
- ANGLE RULES:
74
- - The selected angle must be applied to every headline
75
- - The formula provides the structure
76
- - The angle provides the style
77
- - The angle changes how the headline is expressed, not the structure itself
78
-
79
- AVATAR REALITY RULES:
80
- - Write headlines based on real-life situations the audience experiences
81
- - Focus on specific moments, problems, obstacles, or daily scenarios
82
- - Each headline must describe something the audience can immediately recognize
83
- - Every headline must feel like something that happens on a real day
84
- - Write scenes, not concepts
85
- - Show what is happening, when it happens, or why it matters
86
-
87
- AVOID ABSTRACT PROMISES LIKE:
88
- - improve
89
- - transform
90
- - master
91
- - dominate
92
- - optimize
93
-
94
- BAD EXAMPLES:
95
- - Improve your cooking skills
96
- - Transform your meals
97
- - Master the kitchen
98
-
99
- These are too generic because they describe outcomes without showing a real situation.
100
-
101
- GOOD EXAMPLES:
102
- - Cook something decent when you get home tired and don't know what to prepare
103
- - Prepare dinner fast when unexpected guests arrive
104
- - Stop ordering takeout every time you run out of ideas
105
- """
106
-
107
- headlines_instruction = f"{system_prompt}\n\n"
108
-
109
- if selected_angle != "NINGUNO":
110
- headlines_instruction += f"""
111
- SELECTED ANGLE: {selected_angle}
112
-
113
- ANGLE INSTRUCTION:
114
- {context["angle_instruction"]}
115
-
116
- ANGLE EXAMPLES:
117
- """
118
- for example in context["angle_examples"]:
119
- headlines_instruction += f"- {example}\n"
120
-
121
- headlines_instruction += "\n"
122
-
123
- headlines_instruction += (
124
- f"Your task is to create {number_of_headlines} headlines for {target_audience} "
125
- f"about {product}, using the selected formula"
126
  )
127
 
128
  if selected_angle != "NINGUNO":
129
- headlines_instruction += f" and the angle {selected_angle}"
130
-
131
- headlines_instruction += ".\n\n"
132
-
133
- headlines_instruction += (
134
- f"Before writing, imagine a real day in the life of {target_audience}. "
135
- f"Think about what they want, what frustrates them, what slows them down, "
136
- f"what awkward, stressful, repetitive, annoying, or meaningful moments they experience, "
137
- f"and what kind of situation would make them immediately say: 'yes, that is me.'\n\n"
138
- )
139
-
140
- headlines_instruction += (
141
- f"Do not rely on mentioning {product} explicitly to create interest. "
142
- f"Create interest through the situation, the moment, the tension, the obstacle, or the desire.\n\n"
143
- )
144
-
145
- headlines_instruction += "FORMULA:\n"
146
- headlines_instruction += f"{context['formula_description']}\n\n"
147
-
148
- headlines_instruction += "FORMULA EXAMPLES:\n"
149
- for i, example in enumerate(context["formula_examples"], 1):
150
- headlines_instruction += f"{i}. {example}\n"
151
-
152
- headlines_instruction += "\nGENERATION RULES:\n"
153
- headlines_instruction += "- Keep a structure and length similar to the examples\n"
154
- headlines_instruction += "- Maintain specificity and concreteness\n"
155
- headlines_instruction += "- Use recognizable real-life situations\n"
156
- headlines_instruction += "- Inspire yourself from the examples without copying them literally\n"
157
- headlines_instruction += "- Make every headline feel human, clear, and credible\n"
158
- headlines_instruction += "- Avoid generic promises without context\n"
159
- headlines_instruction += "- Make the audience feel seen in a real moment of life\n\n"
160
-
161
- headlines_instruction += (
162
- f"Generate now {number_of_headlines} original headlines that respect the formula structure"
163
- )
164
 
165
- if selected_angle != "NINGUNO":
166
- headlines_instruction += f" and apply the angle {selected_angle}"
 
 
 
 
167
 
168
- headlines_instruction += ".\n"
169
 
170
  response = client.models.generate_content(
171
  model="gemini-2.5-flash-lite",
172
- contents=headlines_instruction + "\n\nWrite the headlines now.",
173
  config=types.GenerateContentConfig(
174
  temperature=temperature,
175
  top_p=0.65,
176
- max_output_tokens=8196,
177
  ),
178
  )
179
 
180
- if not response.text:
181
- return "No se generaron titulares. Prueba con otra fórmula, ángulo o nivel de creatividad."
182
-
183
  return response.text
184
 
185
 
@@ -203,7 +139,7 @@ st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
203
  # Centrar el título y el subtítulo
204
  st.markdown("<h1 style='text-align: center;'>Enchanted Hooks</h1>", unsafe_allow_html=True)
205
  st.markdown(
206
- "<h4 style='text-align: center;'>Genera titulares más claros, persuasivos y alineados con tu audiencia usando fórmulas y ángulos de copywriting.</h4>",
207
  unsafe_allow_html=True
208
  )
209
 
@@ -226,6 +162,7 @@ with col1:
226
  index=4
227
  )
228
 
 
229
  with st.expander("Personaliza tus titulares"):
230
  temperature = st.slider(
231
  "Creatividad",
@@ -247,6 +184,8 @@ with col1:
247
  )
248
 
249
  selected_formula = headline_formulas[selected_formula_key]
 
 
250
  submit = st.button("Generar Titulares")
251
 
252
  # Mostrar los titulares generados
@@ -266,7 +205,7 @@ if submit:
266
  selected_angle
267
  )
268
 
269
- formatted_headlines = (generated_headlines or "").replace("\n", "<br>")
270
 
271
  col2.markdown(
272
  f"""
 
24
  selected_formula = headline_formulas[selected_formula_key]
25
 
26
  formula_description = selected_formula.get("description", "").strip()
27
+ formula_description_short = " ".join(formula_description.split())[:420]
28
  formula_examples = selected_formula.get("examples", [])
29
 
30
  random_examples = random.sample(
31
  formula_examples,
32
+ min(2, len(formula_examples))
33
  ) if formula_examples else []
34
 
35
  angle_instruction = ""
 
37
 
38
  if selected_angle != "NINGUNO" and selected_angle in angles:
39
  angle_instruction = angles[selected_angle].get("instruction", "").strip()
40
+ angle_examples = angles[selected_angle].get("examples", [])[:1]
41
+
42
+ extra_guidance = [
43
+ f"Escribe para {target_audience} como personas reales, no como una categoría genérica.",
44
+ f"Piensa en qué desea ese público, qué le frustra, qué objeciones tiene y qué transformación busca en relación con {product}.",
45
+ "No copies literalmente los ejemplos.",
46
+ "Haz que cada titular sea claro, atractivo y creíble.",
47
+ "No dependas de mencionar explícitamente el producto para generar interés."
48
+ ]
49
 
50
  return {
51
  "formula_description": formula_description,
52
+ "formula_description_short": formula_description_short,
53
  "formula_examples": random_examples,
54
  "angle_instruction": angle_instruction,
55
+ "angle_examples": angle_examples,
56
+ "extra_guidance": extra_guidance
57
  }
58
 
59
 
 
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:
71
+ Generar titulares atractivos, claros y creíbles para el público indicado.
72
+
73
+ FORMATO OBLIGATORIO:
74
+ - Devuelve EXACTAMENTE {number_of_headlines} líneas.
75
+ - Cada línea debe empezar con número y punto (ejemplo: 1. ...).
76
+ - No agregues introducciones, notas, categorías ni cierre.
77
+ - Una sola idea por línea.
78
+
79
+ CALIDAD:
80
+ - Evita clichés y frases vacías.
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"
97
+ f"INSTRUCCIÓN DE ÁNGULO: {context['angle_instruction']}\n\n"
98
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
+ random_examples = context["formula_examples"]
101
+ if random_examples:
102
+ headlines_instruction += "EJEMPLOS DE REFERENCIA:\n"
103
+ for i, example in enumerate(random_examples, 1):
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(
110
  model="gemini-2.5-flash-lite",
111
+ contents=headlines_instruction + "\n\nEscribe los titulares ahora.",
112
  config=types.GenerateContentConfig(
113
  temperature=temperature,
114
  top_p=0.65,
115
+ max_output_tokens=512,
116
  ),
117
  )
118
 
 
 
 
119
  return response.text
120
 
121
 
 
139
  # Centrar el título y el subtítulo
140
  st.markdown("<h1 style='text-align: center;'>Enchanted Hooks</h1>", unsafe_allow_html=True)
141
  st.markdown(
142
+ "<h4 style='text-align: center;'>Imagina poder conjurar títulos que no solo informan, sino que encantan. Esta app es tu varita mágica en el mundo del copywriting, transformando cada concepto en un titular cautivador que deja a todos deseando más.</h4>",
143
  unsafe_allow_html=True
144
  )
145
 
 
162
  index=4
163
  )
164
 
165
+ # Crear un único acordeón para fórmula, creatividad y ángulo
166
  with st.expander("Personaliza tus titulares"):
167
  temperature = st.slider(
168
  "Creatividad",
 
184
  )
185
 
186
  selected_formula = headline_formulas[selected_formula_key]
187
+
188
+ # Botón de enviar
189
  submit = st.button("Generar Titulares")
190
 
191
  # Mostrar los titulares generados
 
205
  selected_angle
206
  )
207
 
208
+ formatted_headlines = generated_headlines.replace("\n", "<br>")
209
 
210
  col2.markdown(
211
  f"""