Update app.py
Browse files
app.py
CHANGED
@@ -4,85 +4,121 @@ import os
|
|
4 |
import google.generativeai as genai
|
5 |
|
6 |
load_dotenv()
|
7 |
-
|
8 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
13 |
-
full_prompt = f"""
|
14 |
-
You are a skilled copywriter and storyteller. Create a persuasive story in Spanish following the P.A.S.A. formula (Problema, Agitaci贸n, Soluci贸n, Acci贸n).
|
15 |
-
Do not explicitly label or explain each section (Problema, Agitaci贸n, Soluci贸n, Acci贸n). Instead, weave these elements naturally into a cohesive, flowing narrative that emotionally connects with the {target_audience}.
|
16 |
-
The story should have {length} words, with a {mood} tone. Here are the details:
|
17 |
-
1. Problema: Describe a specific problem that keeps the {target_audience} awake at night.
|
18 |
-
2. Agitaci贸n: Amplify the emotional and practical consequences of this problem.
|
19 |
-
3. Soluci贸n: Highlight how the product '{product}' solves this problem and improves their life.
|
20 |
-
4. Acci贸n: Adapt the provided call-to-action '{action}' and craft it in a way that motivates the reader to take immediate steps, using compelling language that encourages them to act.
|
21 |
-
Write a cohesive, engaging, and emotionally resonant narrative tailored to connect with the {target_audience}.
|
22 |
-
"""
|
23 |
-
response = model.generate_content([full_prompt])
|
24 |
-
if response and response.parts:
|
25 |
-
text = response.parts[0].text
|
26 |
-
return text.strip()
|
27 |
-
else:
|
28 |
-
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
model = genai.GenerativeModel("gemini-1.5-flash")
|
33 |
-
full_prompt = f"""
|
34 |
-
You are a skilled copywriter and storyteller. Create a creative and persuasive story in Spanish following the A.D.P. formula (Antes, Despu茅s, Puente).
|
35 |
-
Do not explicitly label or explain each section (Antes, Despu茅s, Puente). Instead, weave these elements naturally into a cohesive, flowing narrative that emotionally connects with the {target_audience}.
|
36 |
-
The story should always be written in the second person (using 't煤') and should have unexpected twists to engage the {target_audience}.
|
37 |
-
The story should have {length} words, with a {mood} tone. Here are the details:
|
38 |
-
|
39 |
-
1. Antes: Describe the current problem and frustrations that you {target_audience} are facing. Create an immersive situation where the reader can recognize themselves.
|
40 |
-
2. Despu茅s: Paint a desired scenario where the problem of {target_audience} is solved and the benefits are clearly evident. Use a surprising twist to show how life can change.
|
41 |
-
3. Puente: Introduce your solution '{product}' as the logical bridge between your frustration and the desired result. Make sure to emphasize the transformation you鈥檒l experience if you take action '{action}'. Conclude with a compelling call to action '{action}' inviting the reader to take immediate steps to improve their situation.
|
42 |
-
Ensure that the story has a creative flow with unexpected turns and keeps the reader hooked, motivating them to act at the end.
|
43 |
-
Write a cohesive, engaging, and emotionally resonant narrative tailored to connect deeply with you, the {target_audience}.
|
44 |
-
"""
|
45 |
-
response = model.generate_content([full_prompt])
|
46 |
-
if response and response.parts:
|
47 |
-
text = response.parts[0].text
|
48 |
-
return text.strip()
|
49 |
-
else:
|
50 |
-
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
3. **Acci贸n**: Conclude with a natural call to action '{action}' that invites the reader to take the next step, based on the lesson or transformation in the story. Tie the benefits of the {product} into the CTA, emphasizing how taking action will help them achieve similar results.
|
71 |
-
For example:
|
72 |
-
- "Lo que aprend铆 es que la vulnerabilidad te conecta con los dem谩s, y t煤 tambi茅n puedes lograrlo si compartes tus experiencias reales. Si deseas experimentar la calma y claridad mental que trae la pr谩ctica del yoga, 煤nete a nuestro webinar y descubre c贸mo el yoga puede ayudarte a gestionar el estr茅s y mejorar tu bienestar."
|
73 |
-
- "Tras superar mi fracaso, entend铆 que la mente y el cuerpo est谩n m谩s conectados de lo que pensaba, y t煤 tambi茅n puedes descubrir ese equilibrio. Si quieres sentirte m谩s tranquilo, centrado y en control, participa en nuestro webinar de yoga y transforma tu vida."
|
74 |
-
- "Lo que descubr铆 es que la pr谩ctica constante te lleva a un cambio profundo, y t煤 tambi茅n puedes lograrlo si decides hacer algo por ti mismo. 脷nete a nuestra sesi贸n de yoga y aprende c贸mo liberarte de tensiones, aumentar tu flexibilidad y encontrar la paz interior."
|
75 |
-
Empower the reader by showing them how the benefits of the {product} can lead to a transformation. The call to action should be clear, inviting them to take immediate steps based on the benefits of the {product}.
|
76 |
-
|
77 |
-
Ensure that the entire narrative flows smoothly, making the call to action feel like a natural next step after the story, rather than a forced conclusion.
|
78 |
-
"""
|
79 |
-
|
80 |
-
response = model.generate_content([full_prompt])
|
81 |
if response and response.parts:
|
82 |
-
|
83 |
-
|
84 |
-
else:
|
85 |
-
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
|
86 |
|
87 |
# Inicializar la aplicaci贸n Streamlit
|
88 |
st.set_page_config(page_title="Generador de Historias", page_icon=":pencil:", layout="wide")
|
|
|
4 |
import google.generativeai as genai
|
5 |
|
6 |
load_dotenv()
|
|
|
7 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
8 |
|
9 |
+
system_prompt = """You are a world-class copywriter, with expertise in crafting hooks, headlines, and subject lines that immediately capture the reader's attention, prompting them to open the email or continue reading.
|
10 |
+
FORMAT RULES:
|
11 |
+
- Each headline must start with number and period
|
12 |
+
- One headline per line
|
13 |
+
- No explanations or categories
|
14 |
+
- Add a line break between each headline
|
15 |
+
- Avoid unnecessary : symbols
|
16 |
+
- Each headline must be a complete and intriguing sentence
|
17 |
+
IMPORTANT ANGLE INSTRUCTIONS:
|
18 |
+
- The selected angle MUST be applied to EVERY headline
|
19 |
+
- The angle modifies HOW the formula is expressed, not its structure
|
20 |
+
- Think of the angle as a "tone overlay" on the formula
|
21 |
+
- The formula provides the structure, the angle provides the style
|
22 |
+
- Both must work together seamlessly
|
23 |
+
FORMAT EXAMPLE:
|
24 |
+
1. Titular 1.
|
25 |
+
2. Titular 2.
|
26 |
+
3. Titular 3.
|
27 |
+
4. Titular 4.
|
28 |
+
5. Titular 5.
|
29 |
+
IMPORTANT:
|
30 |
+
- Each headline must be unique and memorable
|
31 |
+
- Avoid clich茅s and generalities
|
32 |
+
- Maintain an intriguing but credible tone
|
33 |
+
- Adapt speaking language from the audience
|
34 |
+
- Focus on transformative benefits
|
35 |
+
- Follow the selected angle style while maintaining formula structure"""
|
36 |
+
|
37 |
+
story_formulas = {
|
38 |
+
"PASA": {
|
39 |
+
"description": """
|
40 |
+
La f贸rmula P.A.S.A. se estructura de manera natural y fluida:
|
41 |
+
1. **Problema**:
|
42 |
+
- Identificaci贸n del dolor espec铆fico
|
43 |
+
- Situaci贸n actual problem谩tica
|
44 |
+
- Frustraci贸n principal
|
45 |
+
2. **Agitaci贸n**:
|
46 |
+
- Consecuencias emocionales
|
47 |
+
- Impacto en la vida diaria
|
48 |
+
- Costos de no resolver
|
49 |
+
3. **Soluci贸n**:
|
50 |
+
- Presentaci贸n del producto/servicio
|
51 |
+
- Beneficios clave
|
52 |
+
- Transformaci贸n posible
|
53 |
+
4. **Acci贸n**:
|
54 |
+
- Siguiente paso claro
|
55 |
+
- Motivaci贸n para actuar
|
56 |
+
- Beneficio inmediato
|
57 |
+
"""
|
58 |
+
},
|
59 |
+
"ADP": {
|
60 |
+
"description": """
|
61 |
+
La f贸rmula A.D.P. fluye naturalmente:
|
62 |
+
1. **Antes**:
|
63 |
+
- Estado actual
|
64 |
+
- Frustraciones diarias
|
65 |
+
- Situaci贸n problem谩tica
|
66 |
+
2. **Despu茅s**:
|
67 |
+
- Escenario ideal
|
68 |
+
- Beneficios alcanzados
|
69 |
+
- Nueva realidad
|
70 |
+
3. **Puente**:
|
71 |
+
- Conexi贸n soluci贸n-resultado
|
72 |
+
- Transformaci贸n posible
|
73 |
+
- Camino al cambio
|
74 |
+
"""
|
75 |
+
},
|
76 |
+
"GHA": {
|
77 |
+
"description": """
|
78 |
+
La f贸rmula G.H.A. se desarrolla naturalmente:
|
79 |
+
1. **Gancho**:
|
80 |
+
- Apertura impactante
|
81 |
+
- Elemento sorpresa
|
82 |
+
- Conexi贸n inmediata
|
83 |
+
2. **Historia**:
|
84 |
+
- Narrativa envolvente
|
85 |
+
- Desarrollo personal
|
86 |
+
- Aprendizaje clave
|
87 |
+
3. **Acci贸n**:
|
88 |
+
- Conclusi贸n natural
|
89 |
+
- Invitaci贸n clara
|
90 |
+
- Motivaci贸n final
|
91 |
+
"""
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
def generate_story(formula_type, **kwargs):
|
96 |
+
"""Funci贸n unificada para generar historias"""
|
97 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
if formula_type not in story_formulas:
|
100 |
+
raise ValueError("F贸rmula no v谩lida")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
+
formula_description = story_formulas[formula_type]["description"]
|
103 |
+
|
104 |
+
prompt = f"""{system_prompt}
|
105 |
+
|
106 |
+
Como experto copywriter, crea una historia persuasiva en espa帽ol de {kwargs['length']} palabras con un tono {kwargs['mood']}, siguiendo la estructura:
|
107 |
+
|
108 |
+
{formula_description}
|
109 |
+
|
110 |
+
P煤blico objetivo: {kwargs['target_audience']}
|
111 |
+
Producto/Servicio: {kwargs['product']}
|
112 |
+
Llamada a acci贸n: {kwargs['action']}
|
113 |
+
"""
|
114 |
+
|
115 |
+
if formula_type == "GHA" and 'story_topic' in kwargs:
|
116 |
+
prompt += f"\nTema de la historia: {kwargs['story_topic']}"
|
117 |
+
|
118 |
+
response = model.generate_content([prompt])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
if response and response.parts:
|
120 |
+
return response.parts[0].text.strip()
|
121 |
+
raise ValueError("No se pudo generar la historia")
|
|
|
|
|
122 |
|
123 |
# Inicializar la aplicaci贸n Streamlit
|
124 |
st.set_page_config(page_title="Generador de Historias", page_icon=":pencil:", layout="wide")
|