Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -218,6 +218,73 @@ story_formulas = {
|
|
| 218 |
}
|
| 219 |
}
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
def generate_story(formula_type, target_audience, product, action, mood, length, story_topic=None):
|
| 222 |
"""Funci贸n unificada para generar historias"""
|
| 223 |
model = genai.GenerativeModel("gemini-2.0-flash")
|
|
@@ -443,8 +510,14 @@ IMPORTANT FINAL REMINDER:
|
|
| 443 |
story_instruction = f"{natural_instruction}\n\n{story_instruction}"
|
| 444 |
|
| 445 |
response = model.generate_content([story_instruction])
|
| 446 |
-
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
raise ValueError("No se pudo generar la historia")
|
| 449 |
|
| 450 |
# Inicializar la aplicaci贸n Streamlit
|
|
|
|
| 218 |
}
|
| 219 |
}
|
| 220 |
|
| 221 |
+
def generate_headline_for_story(model, story, formula_type, product, target_audience, mood):
|
| 222 |
+
"""Funci贸n para generar un titular basado en la historia y la f贸rmula seleccionada"""
|
| 223 |
+
|
| 224 |
+
# Configurar el prompt seg煤n la f贸rmula seleccionada
|
| 225 |
+
formula_prompts = {
|
| 226 |
+
"GPS": f"""
|
| 227 |
+
Genera un titular usando la f贸rmula GPS (Goal-Period-Solution):
|
| 228 |
+
1. Meta: 驴Qu茅 desea lograr {target_audience}?
|
| 229 |
+
2. Periodo: 驴En qu茅 marco temporal o situaci贸n cotidiana?
|
| 230 |
+
3. Superaci贸n: Usa un conector con toque de humor (sin, incluso si, aunque, etc.)
|
| 231 |
+
|
| 232 |
+
La historia a titular es:
|
| 233 |
+
{story}
|
| 234 |
+
""",
|
| 235 |
+
"AIDA": f"""
|
| 236 |
+
Genera un titular usando la f贸rmula AIDA:
|
| 237 |
+
1. Atenci贸n: Usa un gancho poderoso
|
| 238 |
+
2. Inter茅s: Desarrolla el gancho inicial
|
| 239 |
+
3. Deseo: Amplifica la emoci贸n
|
| 240 |
+
4. Acci贸n: Cierre natural
|
| 241 |
+
|
| 242 |
+
La historia a titular es:
|
| 243 |
+
{story}
|
| 244 |
+
""",
|
| 245 |
+
"4U": f"""
|
| 246 |
+
Genera un titular usando la f贸rmula 4U:
|
| 247 |
+
1. 脷til: Beneficio pr谩ctico
|
| 248 |
+
2. Urgente: Motivador de acci贸n
|
| 249 |
+
3. 脷nico: Diferenciador memorable
|
| 250 |
+
4. Ultra-espec铆fico: Detalles precisos
|
| 251 |
+
|
| 252 |
+
La historia a titular es:
|
| 253 |
+
{story}
|
| 254 |
+
""",
|
| 255 |
+
"N煤merica Suprema": f"""
|
| 256 |
+
Genera un titular usando la F贸rmula Num茅rica Suprema:
|
| 257 |
+
1. Art铆culo plural (Los/Las)
|
| 258 |
+
2. N煤mero espec铆fico
|
| 259 |
+
3. Adjetivo emocional
|
| 260 |
+
4. Palabra clave en plural
|
| 261 |
+
5. Raz贸n
|
| 262 |
+
6. Promesa
|
| 263 |
+
|
| 264 |
+
La historia a titular es:
|
| 265 |
+
{story}
|
| 266 |
+
"""
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
# Usar el prompt predeterminado si la f贸rmula no est谩 en el diccionario
|
| 270 |
+
headline_prompt = formula_prompts.get(formula_type, f"""
|
| 271 |
+
Genera un titular persuasivo y memorable en espa帽ol para la siguiente historia.
|
| 272 |
+
El titular debe:
|
| 273 |
+
- Conectar con {target_audience}
|
| 274 |
+
- Mantener un tono {mood}
|
| 275 |
+
- Ser conciso y memorable
|
| 276 |
+
- No mencionar directamente "{product}"
|
| 277 |
+
- Generar curiosidad y deseo de leer m谩s
|
| 278 |
+
|
| 279 |
+
Historia:
|
| 280 |
+
{story}
|
| 281 |
+
""")
|
| 282 |
+
|
| 283 |
+
response = model.generate_content([headline_prompt])
|
| 284 |
+
if response and response.parts:
|
| 285 |
+
return response.parts[0].text.strip()
|
| 286 |
+
return None
|
| 287 |
+
|
| 288 |
def generate_story(formula_type, target_audience, product, action, mood, length, story_topic=None):
|
| 289 |
"""Funci贸n unificada para generar historias"""
|
| 290 |
model = genai.GenerativeModel("gemini-2.0-flash")
|
|
|
|
| 510 |
story_instruction = f"{natural_instruction}\n\n{story_instruction}"
|
| 511 |
|
| 512 |
response = model.generate_content([story_instruction])
|
| 513 |
+
if response and response.parts:
|
| 514 |
+
story = response.parts[0].text.strip()
|
| 515 |
+
# Generar el titular usando la f贸rmula seleccionada
|
| 516 |
+
headline = generate_headline_for_story(model, story, formula_type, product, target_audience, mood)
|
| 517 |
+
# Combinar titular y historia
|
| 518 |
+
if headline:
|
| 519 |
+
return f"# {headline}\n\n{story}"
|
| 520 |
+
return story
|
| 521 |
raise ValueError("No se pudo generar la historia")
|
| 522 |
|
| 523 |
# Inicializar la aplicaci贸n Streamlit
|