File size: 10,056 Bytes
91a0d7e
a8fd769
 
 
d51e47b
 
a8fd769
d51e47b
659c702
 
de356ae
659c702
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de356ae
659c702
de356ae
659c702
 
de356ae
659c702
 
 
de356ae
 
 
 
6c969bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de356ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
522d135
ec618b2
de356ae
6c969bc
063a515
de356ae
 
522d135
de356ae
 
 
 
ec618b2
7545fe6
de356ae
7545fe6
ec618b2
 
 
de356ae
7545fe6
0226998
ec618b2
6333949
de356ae
a8fd769
de356ae
 
d51e47b
6c969bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ff0df4
522d135
d51e47b
ae4c2eb
 
 
bef3dc5
070b033
 
 
85052d2
34cb5f8
 
a8fd769
1da5874
34cb5f8
4e62a59
 
 
60ce54c
34cb5f8
 
 
1da5874
 
 
 
 
 
34cb5f8
85052d2
34cb5f8
 
 
 
 
 
 
 
 
 
85052d2
ec618b2
85052d2
ec618b2
85052d2
34cb5f8
ec618b2
34cb5f8
 
 
ec618b2
34cb5f8
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
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")
    
# Inicializar la aplicaci贸n Streamlit
st.set_page_config(page_title="Generador de Historias", page_icon=":pencil:", layout="wide")

# T铆tulo y subt铆tulo
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)

# Acorde贸n para elegir la f贸rmula
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."])

# Crear las columnas para el dise帽o (40% para la izquierda, 60% para la derecha)
col1, col2 = st.columns([2, 3])

# Cambiar el comportamiento del slider cuando se seleccione "G.H.A."
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?")

    # Personalizaci贸n adicional
    with st.expander("Personaliza tu historia"):
        mood = st.selectbox("Tono de la historia:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Rom谩ntico"])

        # Ajustar el slider seg煤n la f贸rmula seleccionada
        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.).")

    # Bot贸n para generar contenido
    submit = st.button("Generar mi historia")

# Mostrar el contenido generado en la columna derecha (col2)
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).")