|
from dotenv import load_dotenv |
|
import streamlit as st |
|
import os |
|
import google.generativeai as genai |
|
|
|
load_dotenv() |
|
genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) |
|
|
|
system_prompt = """You are a world-class copywriter, specialized in creating persuasive and captivating stories that emotionally connect with readers and effectively convey messages. |
|
|
|
FORMAT RULES: |
|
- Story must follow the selected formula structure |
|
- Use clear and well-defined paragraphs |
|
- Maintain coherent narrative flow |
|
- Include smooth transitions between sections |
|
- Avoid unnecessary jargon or complex language |
|
- Naturally weave the product and call-to-action into the narrative |
|
- Never explicitly mention "this is the product" or "this is the call-to-action" |
|
|
|
TONE INSTRUCTIONS: |
|
- Selected tone must remain consistent throughout the story |
|
- Tone modifies HOW the narrative is expressed, not its structure |
|
- Think of tone as an "emotional layer" over the formula |
|
- Formula provides structure, tone provides style |
|
- Both elements must work seamlessly together |
|
|
|
KEY ELEMENTS: |
|
- Impactful opening that grabs attention |
|
- Clear and progressive narrative development |
|
- Emotional connection with target audience |
|
- Natural integration of product/service benefits |
|
- Subtle but effective call-to-action woven into the story |
|
- Transformation journey that leads to the solution |
|
|
|
STORYTELLING GUIDELINES: |
|
- Build tension and resolution naturally |
|
- Create relatable scenarios and characters |
|
- Show don't tell (especially for product benefits) |
|
- Use sensory details and emotional triggers |
|
- Lead to the call-to-action organically |
|
|
|
IMPORTANT: |
|
- Each story must be unique and memorable |
|
- Avoid clich茅s and generalities |
|
- Maintain a credible and authentic tone |
|
- Adapt language to target audience |
|
- Focus on transformative benefits |
|
- Follow formula structure while maintaining chosen tone |
|
- Never make the product placement feel forced |
|
- Ensure call-to-action feels like a natural next step in the story""" |
|
|
|
story_formulas = { |
|
"PASA": { |
|
"description": """ |
|
The P.A.S.A. formula flows naturally through these key elements: |
|
1. **Problem (Problema)**: |
|
- Identify the core pain point |
|
- Current problematic situation |
|
- Main frustration or challenge |
|
- Hidden fears and concerns |
|
- Daily struggles |
|
- Unfulfilled desires |
|
|
|
2. **Agitation (Agitaci贸n)**: |
|
- Emotional consequences |
|
- Daily life impact |
|
- Cost of inaction |
|
- Future implications |
|
- Missed opportunities |
|
- Social and personal effects |
|
- Ripple effects on relationships |
|
- Professional implications |
|
|
|
3. **Solution (Soluci贸n)**: |
|
- Product/service introduction |
|
- Key benefits and features |
|
- Transformation journey |
|
- Success stories |
|
- Unique value proposition |
|
- Immediate relief points |
|
- Long-term advantages |
|
- Social proof elements |
|
|
|
4. **Action (Acci贸n)**: |
|
- Clear next steps |
|
- Motivation triggers |
|
- Immediate benefits |
|
- Sense of urgency |
|
- Risk reversal |
|
- Value-packed offer |
|
- Easy implementation |
|
- Quick-start guide |
|
""" |
|
}, |
|
"GHA": { |
|
"description": """ |
|
La f贸rmula G.H.A. se desarrolla naturalmente: |
|
1. **Gancho**: |
|
- Apertura impactante |
|
- Elemento sorpresa |
|
- Conexi贸n inmediata |
|
2. **Historia**: |
|
- Narrativa envolvente |
|
- Desarrollo personal |
|
- Aprendizaje clave |
|
3. **Acci贸n**: |
|
- Conclusi贸n natural |
|
- Invitaci贸n clara |
|
- Motivaci贸n final |
|
""" |
|
} |
|
} |
|
|
|
def generate_story(formula_type, target_audience, product, action, mood, length, story_topic=None): |
|
"""Funci贸n unificada para generar historias""" |
|
model = genai.GenerativeModel("gemini-2.0-flash") |
|
|
|
if formula_type not in story_formulas: |
|
raise ValueError("F贸rmula no v谩lida") |
|
|
|
formula_description = story_formulas[formula_type]["description"] |
|
|
|
prompt = f"""{system_prompt} |
|
|
|
Como experto copywriter, crea una historia persuasiva en espa帽ol de {length} palabras con un tono {mood}, siguiendo la estructura: |
|
|
|
{formula_description} |
|
|
|
P煤blico objetivo: {target_audience} |
|
Producto/Servicio: {product} |
|
Llamada a acci贸n: {action} |
|
""" |
|
|
|
if formula_type == "GHA" and story_topic: |
|
prompt += f"\nTema de la historia: {story_topic}" |
|
|
|
response = model.generate_content([prompt]) |
|
if response and response.parts: |
|
return response.parts[0].text.strip() |
|
raise ValueError("No se pudo generar la historia") |
|
|
|
if formula_type == "PASA": |
|
prompt = f""" |
|
As a master copywriter and storyteller, craft a compelling {length}-word story in Spanish that follows the P.A.S.A. formula while maintaining a {mood} tone. |
|
|
|
TARGET AUDIENCE PROFILE: |
|
{target_audience} |
|
|
|
STORYTELLING GUIDELINES: |
|
- Weave a natural narrative that flows seamlessly through problem, agitation, solution, and action |
|
- DO NOT explicitly label these sections |
|
- Create an emotional connection through relatable scenarios |
|
- Use sensory details and vivid descriptions |
|
- Maintain consistent tone and voice throughout |
|
|
|
KEY ELEMENTS TO INCLUDE: |
|
1. Opening Hook: |
|
- Identify a specific problem that resonates with {target_audience} |
|
- Create immediate recognition and empathy |
|
- Use powerful emotional triggers |
|
|
|
2. Problem Amplification: |
|
- Explore deeper emotional impact |
|
- Show ripple effects in daily life |
|
- Build tension through real consequences |
|
- Address hidden fears and frustrations |
|
|
|
3. Solution Development: |
|
- Naturally introduce '{product}' as the answer |
|
- Show transformation journey |
|
- Highlight key benefits without being sales-y |
|
- Include subtle social proof elements |
|
|
|
4. Action Integration: |
|
- Weave in '{action}' naturally |
|
- Create urgency without pressure |
|
- Make next steps clear and appealing |
|
- End with emotional satisfaction |
|
|
|
IMPORTANT: |
|
- Maintain natural flow and cohesion |
|
- Avoid explicit marketing language |
|
- Keep product placement subtle but effective |
|
- Ensure call-to-action feels like a logical next step |
|
- Use language that resonates with {target_audience} |
|
""" |
|
|
|
response = model.generate_content([prompt]) |
|
if response and response.parts: |
|
return response.parts[0].text.strip() |
|
raise ValueError("No se pudo generar la historia") |
|
|
|
|
|
st.set_page_config(page_title="Generador de Historias", page_icon=":pencil:", layout="wide") |
|
|
|
|
|
st.markdown("<h1 style='text-align: center;'>Story Genius Maker</h1>", unsafe_allow_html=True) |
|
st.markdown("<h3 style='text-align: center;'>Teje historias inolvidables en segundos, guiado por la magia de la inteligencia artificial que da vida a tus ideas en relatos cautivadores.</h3>", unsafe_allow_html=True) |
|
|
|
|
|
with st.expander("Selecciona la f贸rmula para generar tu historia"): |
|
formula = st.radio("Selecciona la f贸rmula para generar tu historia:", ["P.A.S.A.", "A.D.P.", "G.H.A."]) |
|
|
|
|
|
col1, col2 = st.columns([2, 3]) |
|
|
|
|
|
with col1: |
|
target_audience = st.text_input("P煤blico objetivo", placeholder="驴A qui茅n est谩 dirigido tu mensaje?") |
|
product = st.text_input("Producto/Servicio", placeholder="驴Qu茅 est谩s ofreciendo?") |
|
action = st.text_area("Llamado a la acci贸n", placeholder="驴Qu茅 acci贸n espec铆fica debe tomar tu audiencia?") |
|
|
|
|
|
with st.expander("Personaliza tu historia"): |
|
mood = st.selectbox("Tono de la historia:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"]) |
|
|
|
|
|
if formula == "G.H.A.": |
|
length = st.slider("Longitud de la historia (palabras):", min_value=50, max_value=200, value=150, step=10) |
|
else: |
|
length = st.slider("Longitud de la historia (palabras):", min_value=50, max_value=150, value=100, step=10) |
|
|
|
if formula == "G.H.A.": |
|
story_topic = st.text_area("De qu茅 quieres que trate la historia", placeholder="Explica si hay algo espec铆fico sobre lo que te gustar铆a contar (puede ser una vivencia personal, pel铆cula, cuento, personaje ficticio, etc.).") |
|
|
|
|
|
submit = st.button("Generar mi historia") |
|
|
|
|
|
with col2: |
|
if submit: |
|
if target_audience and product and action: |
|
try: |
|
if formula == "P.A.S.A.": |
|
response = generate_story("PASA", target_audience, product, action, mood, length) |
|
elif formula == "A.D.P.": |
|
response = generate_story("ADP", target_audience, product, action, mood, length) |
|
elif formula == "G.H.A.": |
|
if story_topic: |
|
response = generate_story("GHA", target_audience, product, action, mood, length, story_topic) |
|
else: |
|
st.error("Por favor, completa todos los campos requeridos para la f贸rmula G.H.A.") |
|
response = "" |
|
|
|
if response: |
|
st.subheader("Historia generada:") |
|
st.write(response) |
|
except ValueError as e: |
|
st.error(f"Error: {str(e)}") |
|
else: |
|
st.error("Por favor, completa todos los campos requeridos (P煤blico objetivo, Producto y Acci贸n).") |
|
|