Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
| 16 |
# Fórmulas con ejemplos y explicaciones
|
| 17 |
# headline_formulas dictionary has been moved to formulas/headline_formulas.py
|
| 18 |
|
| 19 |
-
def generate_headlines(number_of_headlines, target_audience, product, temperature, selected_formula, selected_angle):
|
| 20 |
# Crear la configuración del modelo
|
| 21 |
generation_config = {
|
| 22 |
"temperature": temperature,
|
|
@@ -72,6 +72,18 @@ IMPORTANT:
|
|
| 72 |
# Iniciar el prompt con las instrucciones del sistema
|
| 73 |
headlines_instruction = f"{system_prompt}\n\n"
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# Añadir instrucciones de ángulo solo si no es "NINGUNO"
|
| 76 |
if selected_angle != "NINGUNO":
|
| 77 |
headlines_instruction += f"""
|
|
@@ -79,79 +91,79 @@ IMPORTANT:
|
|
| 79 |
INSTRUCCIONES DE ÁNGULO ESPECÍFICAS:
|
| 80 |
{angles[selected_angle]["instruction"]}
|
| 81 |
|
| 82 |
-
|
| 83 |
-
1.
|
| 84 |
-
2.
|
| 85 |
-
3.
|
| 86 |
-
4.
|
| 87 |
|
| 88 |
-
|
| 89 |
"""
|
| 90 |
for example in angles[selected_angle]["examples"]:
|
| 91 |
headlines_instruction += f"- {example}\n"
|
| 92 |
|
| 93 |
headlines_instruction += (
|
| 94 |
-
f"\
|
| 95 |
-
f"
|
| 96 |
)
|
| 97 |
|
| 98 |
if selected_angle != "NINGUNO":
|
| 99 |
-
headlines_instruction += f"
|
| 100 |
|
| 101 |
headlines_instruction += (
|
| 102 |
-
f"
|
| 103 |
)
|
| 104 |
|
| 105 |
if selected_angle != "NINGUNO":
|
| 106 |
-
headlines_instruction += f"
|
| 107 |
|
| 108 |
headlines_instruction += ".\n\n"
|
| 109 |
|
| 110 |
headlines_instruction += (
|
| 111 |
-
f"
|
| 112 |
-
f"
|
| 113 |
)
|
| 114 |
|
| 115 |
if selected_angle != "NINGUNO":
|
| 116 |
-
headlines_instruction += f",
|
| 117 |
|
| 118 |
headlines_instruction += ":\n\n"
|
| 119 |
|
| 120 |
-
#
|
| 121 |
random_examples = random.sample(selected_formula['examples'], min(5, len(selected_formula['examples'])))
|
| 122 |
|
| 123 |
-
headlines_instruction += "
|
| 124 |
for i, example in enumerate(random_examples, 1):
|
| 125 |
headlines_instruction += f"{i}. {example}\n"
|
| 126 |
|
| 127 |
-
headlines_instruction += "\
|
| 128 |
-
headlines_instruction += "1.
|
| 129 |
-
headlines_instruction += "2.
|
| 130 |
-
headlines_instruction += "3.
|
| 131 |
-
headlines_instruction += "4.
|
| 132 |
-
headlines_instruction += f"5.
|
| 133 |
|
| 134 |
-
headlines_instruction += f"
|
| 135 |
|
| 136 |
-
#
|
| 137 |
if selected_angle != "NINGUNO":
|
| 138 |
headlines_instruction += f"""
|
| 139 |
-
|
| 140 |
-
1.
|
| 141 |
-
2.
|
| 142 |
-
3.
|
| 143 |
-
4.
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
"""
|
| 148 |
else:
|
| 149 |
headlines_instruction += f"""
|
| 150 |
-
|
| 151 |
-
|
| 152 |
"""
|
| 153 |
|
| 154 |
-
#
|
| 155 |
chat_session = model.start_chat(
|
| 156 |
history=[
|
| 157 |
{
|
|
@@ -192,16 +204,26 @@ col1, col2 = st.columns([1, 2])
|
|
| 192 |
with col1:
|
| 193 |
target_audience = st.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Estudiantes Universitarios")
|
| 194 |
product = st.text_input("¿Qué producto tienes en mente?", placeholder="Ejemplo: Curso de Inglés")
|
| 195 |
-
|
| 196 |
-
|
| 197 |
# Crear un único acordeón para fórmula, creatividad y ángulo
|
| 198 |
with st.expander("Personaliza tus titulares"):
|
| 199 |
-
|
| 200 |
-
|
| 201 |
selected_formula_key = st.selectbox(
|
| 202 |
"Selecciona una fórmula para tus titulares",
|
| 203 |
options=list(headline_formulas.keys())
|
| 204 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
# Automatically use the keys from the angles dictionary
|
| 207 |
# Make sure "NINGUNO" appears first, then the rest alphabetically
|
|
@@ -221,9 +243,10 @@ if submit:
|
|
| 221 |
# Check if we have valid inputs
|
| 222 |
has_product = product.strip() != ""
|
| 223 |
has_audience = target_audience.strip() != ""
|
|
|
|
| 224 |
|
| 225 |
-
# Valid combination: Product + Audience
|
| 226 |
-
valid_inputs = has_product and has_audience
|
| 227 |
|
| 228 |
if valid_inputs and selected_formula:
|
| 229 |
try:
|
|
@@ -233,7 +256,8 @@ if submit:
|
|
| 233 |
product,
|
| 234 |
temperature,
|
| 235 |
selected_formula,
|
| 236 |
-
selected_angle
|
|
|
|
| 237 |
)
|
| 238 |
col2.markdown(f"""
|
| 239 |
<div class="results-container">
|
|
@@ -246,5 +270,5 @@ if submit:
|
|
| 246 |
else:
|
| 247 |
if not selected_formula:
|
| 248 |
col2.error("Por favor, selecciona una fórmula.")
|
| 249 |
-
|
| 250 |
-
col2.error("Por favor, proporciona el público objetivo y el producto.")
|
|
|
|
| 16 |
# Fórmulas con ejemplos y explicaciones
|
| 17 |
# headline_formulas dictionary has been moved to formulas/headline_formulas.py
|
| 18 |
|
| 19 |
+
def generate_headlines(number_of_headlines, target_audience, product, temperature, selected_formula, selected_angle, base_copy=None):
|
| 20 |
# Crear la configuración del modelo
|
| 21 |
generation_config = {
|
| 22 |
"temperature": temperature,
|
|
|
|
| 72 |
# Iniciar el prompt con las instrucciones del sistema
|
| 73 |
headlines_instruction = f"{system_prompt}\n\n"
|
| 74 |
|
| 75 |
+
# Add base copy instructions if provided
|
| 76 |
+
if base_copy and base_copy.strip():
|
| 77 |
+
headlines_instruction += f"""
|
| 78 |
+
BASE COPY TO USE:
|
| 79 |
+
The following text should be used as the primary source of information and inspiration for generating headlines:
|
| 80 |
+
|
| 81 |
+
{base_copy}
|
| 82 |
+
|
| 83 |
+
IMPORTANT: Extract key concepts, benefits, and language from this base copy to create your headlines.
|
| 84 |
+
Use the tone, style, and specific terminology from this text whenever possible.
|
| 85 |
+
"""
|
| 86 |
+
|
| 87 |
# Añadir instrucciones de ángulo solo si no es "NINGUNO"
|
| 88 |
if selected_angle != "NINGUNO":
|
| 89 |
headlines_instruction += f"""
|
|
|
|
| 91 |
INSTRUCCIONES DE ÁNGULO ESPECÍFICAS:
|
| 92 |
{angles[selected_angle]["instruction"]}
|
| 93 |
|
| 94 |
+
IMPORTANT: The angle {selected_angle} must be applied as a "style layer" over the formula structure:
|
| 95 |
+
1. Keep the base structure of the formula intact
|
| 96 |
+
2. Apply the tone and style of the angle {selected_angle}
|
| 97 |
+
3. Ensure that each element of the formula reflects the angle
|
| 98 |
+
4. The angle affects "how" it is said, not "what" is said
|
| 99 |
|
| 100 |
+
SUCCESSFUL EXAMPLES OF THE ANGLE {selected_angle}:
|
| 101 |
"""
|
| 102 |
for example in angles[selected_angle]["examples"]:
|
| 103 |
headlines_instruction += f"- {example}\n"
|
| 104 |
|
| 105 |
headlines_instruction += (
|
| 106 |
+
f"\nYour task is to create {number_of_headlines} irresistible headlines for {target_audience} "
|
| 107 |
+
f"that instantly capture attention and generate curiosity about {product}. "
|
| 108 |
)
|
| 109 |
|
| 110 |
if selected_angle != "NINGUNO":
|
| 111 |
+
headlines_instruction += f"IMPORTANT: Each headline MUST follow the {selected_angle} angle clearly and consistently.\n\n"
|
| 112 |
|
| 113 |
headlines_instruction += (
|
| 114 |
+
f"Avoid obvious mentions of {product} and focus on awakening genuine interest"
|
| 115 |
)
|
| 116 |
|
| 117 |
if selected_angle != "NINGUNO":
|
| 118 |
+
headlines_instruction += f" using the selected angle"
|
| 119 |
|
| 120 |
headlines_instruction += ".\n\n"
|
| 121 |
|
| 122 |
headlines_instruction += (
|
| 123 |
+
f"IMPORTANT: Carefully study these examples of the selected formula. "
|
| 124 |
+
f"Each example represents the style and structure to follow"
|
| 125 |
)
|
| 126 |
|
| 127 |
if selected_angle != "NINGUNO":
|
| 128 |
+
headlines_instruction += f", adapted to the {selected_angle} angle"
|
| 129 |
|
| 130 |
headlines_instruction += ":\n\n"
|
| 131 |
|
| 132 |
+
# Add 5 random examples of the formula
|
| 133 |
random_examples = random.sample(selected_formula['examples'], min(5, len(selected_formula['examples'])))
|
| 134 |
|
| 135 |
+
headlines_instruction += "FORMULA EXAMPLES TO FOLLOW:\n"
|
| 136 |
for i, example in enumerate(random_examples, 1):
|
| 137 |
headlines_instruction += f"{i}. {example}\n"
|
| 138 |
|
| 139 |
+
headlines_instruction += "\nSPECIFIC INSTRUCTIONS:\n"
|
| 140 |
+
headlines_instruction += "1. Maintain the same structure and length as the previous examples\n"
|
| 141 |
+
headlines_instruction += "2. Use the same tone and writing style\n"
|
| 142 |
+
headlines_instruction += "3. Replicate the patterns of phrase construction\n"
|
| 143 |
+
headlines_instruction += "4. Preserve the level of specificity and detail\n"
|
| 144 |
+
headlines_instruction += f"5. Adapt the content for {target_audience} while maintaining the essence of the examples\n\n"
|
| 145 |
|
| 146 |
+
headlines_instruction += f"FORMULA TO FOLLOW:\n{selected_formula['description']}\n\n"
|
| 147 |
|
| 148 |
+
# CORRECT (with indentation):
|
| 149 |
if selected_angle != "NINGUNO":
|
| 150 |
headlines_instruction += f"""
|
| 151 |
+
FINAL REMINDER:
|
| 152 |
+
1. Follow the structure of the selected formula
|
| 153 |
+
2. Apply the angle as a "style layer"
|
| 154 |
+
3. Maintain coherence between formula and angle
|
| 155 |
+
4. Ensure each headline reflects both elements
|
| 156 |
+
|
| 157 |
+
GENERATE NOW:
|
| 158 |
+
Create {number_of_headlines} headlines that faithfully follow the style and structure of the examples shown.
|
| 159 |
"""
|
| 160 |
else:
|
| 161 |
headlines_instruction += f"""
|
| 162 |
+
GENERATE NOW:
|
| 163 |
+
Create {number_of_headlines} headlines that faithfully follow the style and structure of the examples shown.
|
| 164 |
"""
|
| 165 |
|
| 166 |
+
# Send the message to the model (without image conditions)
|
| 167 |
chat_session = model.start_chat(
|
| 168 |
history=[
|
| 169 |
{
|
|
|
|
| 204 |
with col1:
|
| 205 |
target_audience = st.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Estudiantes Universitarios")
|
| 206 |
product = st.text_input("¿Qué producto tienes en mente?", placeholder="Ejemplo: Curso de Inglés")
|
| 207 |
+
|
|
|
|
| 208 |
# Crear un único acordeón para fórmula, creatividad y ángulo
|
| 209 |
with st.expander("Personaliza tus titulares"):
|
| 210 |
+
# Moved formula selection above number of headlines
|
|
|
|
| 211 |
selected_formula_key = st.selectbox(
|
| 212 |
"Selecciona una fórmula para tus titulares",
|
| 213 |
options=list(headline_formulas.keys())
|
| 214 |
)
|
| 215 |
+
|
| 216 |
+
# Added number of headlines after formula selection
|
| 217 |
+
number_of_headlines = st.selectbox("Número de Titulares", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=4)
|
| 218 |
+
|
| 219 |
+
# New text area for base copy
|
| 220 |
+
base_copy = st.text_area(
|
| 221 |
+
"Texto base para generar titulares (opcional)",
|
| 222 |
+
placeholder="Agrega aquí un texto que sirva como base para generar los titulares. Si lo dejas vacío, se generarán basados en el producto y público objetivo.",
|
| 223 |
+
height=150
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
temperature = st.slider("Creatividad", min_value=0.0, max_value=2.0, value=1.0, step=0.1)
|
| 227 |
|
| 228 |
# Automatically use the keys from the angles dictionary
|
| 229 |
# Make sure "NINGUNO" appears first, then the rest alphabetically
|
|
|
|
| 243 |
# Check if we have valid inputs
|
| 244 |
has_product = product.strip() != ""
|
| 245 |
has_audience = target_audience.strip() != ""
|
| 246 |
+
has_base_copy = base_copy and base_copy.strip() != ""
|
| 247 |
|
| 248 |
+
# Valid combination: Either (Product + Audience) or Base Copy
|
| 249 |
+
valid_inputs = (has_product and has_audience) or has_base_copy
|
| 250 |
|
| 251 |
if valid_inputs and selected_formula:
|
| 252 |
try:
|
|
|
|
| 256 |
product,
|
| 257 |
temperature,
|
| 258 |
selected_formula,
|
| 259 |
+
selected_angle,
|
| 260 |
+
base_copy if has_base_copy else None
|
| 261 |
)
|
| 262 |
col2.markdown(f"""
|
| 263 |
<div class="results-container">
|
|
|
|
| 270 |
else:
|
| 271 |
if not selected_formula:
|
| 272 |
col2.error("Por favor, selecciona una fórmula.")
|
| 273 |
+
elif not has_base_copy:
|
| 274 |
+
col2.error("Por favor, proporciona el público objetivo y el producto, o un texto base.")
|