JeCabrera commited on
Commit
f018800
·
verified ·
1 Parent(s): c66c797

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -40
app.py CHANGED
@@ -38,20 +38,11 @@ def build_headline_context(selected_formula_key, selected_angle, target_audience
38
  angle_instruction = angles[selected_angle].get("instruction", "").strip()
39
  angle_examples = angles[selected_angle].get("examples", [])[:3]
40
 
41
- extra_guidance = [
42
- f"Escribe para {target_audience} como personas reales, no como una categoría genérica.",
43
- f"Piensa en qué desea ese público, qué le frustra, qué objeciones tiene y qué transformación busca en relación con {product}.",
44
- "No copies literalmente los ejemplos.",
45
- "Haz que cada titular sea claro, atractivo y creíble.",
46
- "No dependas de mencionar explícitamente el producto para generar interés."
47
- ]
48
-
49
  return {
50
  "formula_description": formula_description,
51
  "formula_examples": random_examples,
52
  "angle_instruction": angle_instruction,
53
- "angle_examples": angle_examples,
54
- "extra_guidance": extra_guidance
55
  }
56
 
57
 
@@ -77,71 +68,108 @@ CORE RULES:
77
  - Avoid clichés and generic language
78
  - Keep the tone intriguing but credible
79
  - Use language that feels natural for the target audience
80
- - Focus on clear and desirable benefits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  """
82
 
83
  headlines_instruction = f"{system_prompt}\n\n"
84
 
85
  if selected_angle != "NINGUNO":
86
  headlines_instruction += f"""
87
- ÁNGULO PRINCIPAL: {selected_angle}
88
- Usa este ángulo como una capa de estilo. Modifica cómo se expresa el titular, no la estructura de la fórmula.
89
 
90
- INSTRUCCIÓN DEL ÁNGULO:
91
  {context["angle_instruction"]}
92
 
93
- EJEMPLOS DEL ÁNGULO:
94
  """
95
  for example in context["angle_examples"]:
96
  headlines_instruction += f"- {example}\n"
97
 
 
 
98
  headlines_instruction += (
99
- f"\nTu tarea es crear {number_of_headlines} titulares para {target_audience} "
100
- f"sobre {product}, usando la fórmula seleccionada"
101
  )
102
 
103
  if selected_angle != "NINGUNO":
104
- headlines_instruction += f" y el ángulo {selected_angle}"
105
 
106
  headlines_instruction += ".\n\n"
107
 
108
  headlines_instruction += (
109
- f"Antes de escribir, piensa en {target_audience} como personas reales: "
110
- f"qué desean, qué les frustra, qué objeciones tienen y qué transformación buscan. "
111
- f"Haz que cada titular conecte con esa realidad de forma natural.\n\n"
 
112
  )
113
 
114
  headlines_instruction += (
115
- f"No dependas de mencionar explícitamente {product} para generar interés.\n\n"
 
116
  )
117
 
118
- random_examples = context["formula_examples"]
119
-
120
- headlines_instruction += "FÓRMULA:\n"
121
  headlines_instruction += f"{context['formula_description']}\n\n"
122
 
123
- headlines_instruction += "EJEMPLOS:\n"
124
- for i, example in enumerate(random_examples, 1):
125
  headlines_instruction += f"{i}. {example}\n"
126
 
127
- headlines_instruction += "\nREGLAS DE GENERACIÓN:\n"
128
- headlines_instruction += "- Mantén una estructura y longitud similares a las de los ejemplos\n"
129
- headlines_instruction += "- Conserva la especificidad y el nivel de detalle\n"
130
- headlines_instruction += "- Inspírate en los patrones sin copiar literalmente\n"
131
- headlines_instruction += "- Haz que cada titular suene natural, claro y creíble\n\n"
 
 
 
132
 
133
  headlines_instruction += (
134
- f"Genera ahora {number_of_headlines} titulares originales que respeten la estructura de la fórmula"
135
  )
136
 
137
  if selected_angle != "NINGUNO":
138
- headlines_instruction += f" y apliquen el ángulo {selected_angle}"
139
 
140
  headlines_instruction += ".\n"
141
 
142
  response = client.models.generate_content(
143
  model="gemini-2.5-flash-lite",
144
- contents=headlines_instruction + "\n\nEscribe los titulares ahora.",
145
  config=types.GenerateContentConfig(
146
  temperature=temperature,
147
  top_p=0.65,
@@ -149,6 +177,9 @@ EJEMPLOS DEL ÁNGULO:
149
  ),
150
  )
151
 
 
 
 
152
  return response.text
153
 
154
 
@@ -172,7 +203,7 @@ st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
172
  # Centrar el título y el subtítulo
173
  st.markdown("<h1 style='text-align: center;'>Enchanted Hooks</h1>", unsafe_allow_html=True)
174
  st.markdown(
175
- "<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>",
176
  unsafe_allow_html=True
177
  )
178
 
@@ -195,7 +226,6 @@ with col1:
195
  index=4
196
  )
197
 
198
- # Crear un único acordeón para fórmula, creatividad y ángulo
199
  with st.expander("Personaliza tus titulares"):
200
  temperature = st.slider(
201
  "Creatividad",
@@ -217,8 +247,6 @@ with col1:
217
  )
218
 
219
  selected_formula = headline_formulas[selected_formula_key]
220
-
221
- # Botón de enviar
222
  submit = st.button("Generar Titulares")
223
 
224
  # Mostrar los titulares generados
@@ -238,7 +266,7 @@ if submit:
238
  selected_angle
239
  )
240
 
241
- formatted_headlines = generated_headlines.replace("\n", "<br>")
242
 
243
  col2.markdown(
244
  f"""
 
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
 
 
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,
 
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
  # 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
  index=4
227
  )
228
 
 
229
  with st.expander("Personaliza tus titulares"):
230
  temperature = st.slider(
231
  "Creatividad",
 
247
  )
248
 
249
  selected_formula = headline_formulas[selected_formula_key]
 
 
250
  submit = st.button("Generar Titulares")
251
 
252
  # Mostrar los titulares generados
 
266
  selected_angle
267
  )
268
 
269
+ formatted_headlines = (generated_headlines or "").replace("\n", "<br>")
270
 
271
  col2.markdown(
272
  f"""