JeCabrera commited on
Commit
e3db149
·
verified ·
1 Parent(s): 5979385

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +170 -144
app.py CHANGED
@@ -1,145 +1,171 @@
1
- from dotenv import load_dotenv
2
- import streamlit as st
3
- import os
4
- import google.generativeai as genai
5
- from cta_formulas import cta_formulas
6
- from styles import apply_styles
7
- from tone_formulas import tone_settings
8
-
9
- # Cargar variables de entorno
10
- load_dotenv()
11
-
12
- # Configurar API de Google Gemini
13
- genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
14
-
15
- def get_gemini_response(product_service, target_audience, desired_action, formula_type, tone_type, temperature):
16
- if not product_service or not target_audience or not desired_action:
17
- return "Por favor, completa todos los campos requeridos."
18
-
19
- formula = cta_formulas[formula_type]
20
- tone = tone_settings[tone_type] # Add this line
21
-
22
- model = genai.GenerativeModel('gemini-2.0-flash')
23
- full_prompt = f"""
24
- You are an expert copywriter specialized in creating persuasive Calls to Action (CTAs).
25
- Analyze (internally, don't include in output) the following information:
26
-
27
- BUSINESS INFORMATION:
28
- Product/Service: {product_service}
29
- Target Audience: {target_audience}
30
- Desired Action: {desired_action}
31
- CTA Type: {formula_type}
32
- Tone Style: {tone['style']}
33
- Keywords to consider: {', '.join(tone['keywords'])}
34
- {formula["description"]}
35
-
36
- EXAMPLES TO FOLLOW:
37
- {formula["examples"]}
38
-
39
- First, analyze (but don't show) these points:
40
- 1. TARGET AUDIENCE ANALYSIS:
41
- - What motivates them to take action?
42
- - What obstacles prevent them from acting?
43
- - What immediate benefits are they seeking?
44
- - What fears or doubts do they have?
45
- - What language and tone resonates with them?
46
-
47
- 2. PERSUASION ELEMENTS:
48
- - How to make the desired action more appealing?
49
- - What emotional triggers will resonate most?
50
- - How to create a sense of urgency naturally?
51
- - What unique value proposition to emphasize?
52
- - How to minimize perceived risk?
53
-
54
- Based on your internal analysis, create FIVE different CTAs following EXACTLY the formula structure:
55
- {formula["description"]}
56
-
57
- CRITICAL INSTRUCTIONS:
58
- - Follow the exact formula structure shown in the description above
59
- - Create FIVE different CTAs using the same formula pattern
60
- - ALL CTAs MUST BE IN SPANISH
61
-
62
- Use these examples as reference for the formula structure:
63
- {formula["examples"]}
64
- Output EXACTLY in this format based on {formula_type}:
65
- 1. Follow format from {formula["examples"]}
66
-
67
- 2. Follow format from {formula["examples"]}
68
-
69
- 3. Follow format from {formula["examples"]}
70
- """
71
-
72
- response = model.generate_content([full_prompt], generation_config={"temperature": temperature})
73
- return response.parts[0].text if response and response.parts else "Error al generar contenido."
74
-
75
- # Configurar la aplicación Streamlit
76
- st.set_page_config(page_title="CTA Generator", page_icon="🎯", layout="wide")
77
-
78
- # Leer y mostrar el manual en el sidebar
79
- with open("manual.md", "r", encoding="utf-8") as file:
80
- manual_content = file.read()
81
- st.sidebar.markdown(manual_content)
82
-
83
- # Aplicar estilos
84
- st.markdown(apply_styles(), unsafe_allow_html=True)
85
-
86
- # Título de la app
87
- st.markdown("<h1>Generador de CTAs Persuasivos</h1>", unsafe_allow_html=True)
88
- st.markdown("<h3>Crea llamados a la acción que motiven a tu audiencia a dar el siguiente paso.</h3>", unsafe_allow_html=True)
89
-
90
- # Remove the duplicate manual expander from here
91
-
92
- # Crear dos columnas
93
- col1, col2 = st.columns([0.4, 0.6]) # 40% for left column, 60% for right column
94
-
95
- # Columna izquierda para inputs
96
- with col1:
97
- target_audience = st.text_area(
98
- "¿Cuál es tu público objetivo?",
99
- placeholder="Ejemplo: Emprendedores que buscan automatizar su negocio..."
100
- )
101
-
102
- product_service = st.text_area(
103
- "¿Cuál es tu producto o servicio?",
104
- placeholder="Ejemplo: Curso de automatización con IA, Software de gestión..."
105
- )
106
-
107
- desired_action = st.text_area(
108
- "¿Qué acción quieres que realicen?",
109
- placeholder="Ejemplo: Registrarse al webinar, Descargar la guía gratuita..."
110
- )
111
-
112
- with st.expander("Opciones avanzadas"):
113
- formula_type = st.selectbox(
114
- "Tipo de CTA:",
115
- options=list(cta_formulas.keys())
116
- )
117
-
118
- tone_type = st.selectbox(
119
- "Tono del CTA:",
120
- options=list(tone_settings.keys()),
121
- )
122
-
123
- temperature = st.slider(
124
- "Nivel de creatividad:",
125
- min_value=0.0,
126
- max_value=2.0,
127
- value=1.0,
128
- step=0.1,
129
- help="Valores más altos generan CTAs más creativos pero menos predecibles."
130
- )
131
-
132
- generate_button = st.button("Generar CTAs")
133
-
134
- # Columna derecha para resultados
135
- with col2:
136
- if generate_button and (response := get_gemini_response(
137
- product_service,
138
- target_audience,
139
- desired_action,
140
- formula_type,
141
- tone_type,
142
- temperature
143
- )):
144
- st.markdown("### Tus Llamados a la Acción")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  st.write(response)
 
1
+ from dotenv import load_dotenv
2
+ import streamlit as st
3
+ import os
4
+ import google.generativeai as genai
5
+ from cta_formulas import cta_formulas
6
+ from styles import apply_styles
7
+ from tone_formulas import tone_settings
8
+
9
+ # Cargar variables de entorno
10
+ load_dotenv()
11
+
12
+ # Configurar API de Google Gemini
13
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
14
+
15
+ def get_gemini_response(product_service, target_audience, desired_action, formula_type, tone_type, temperature, postdata_theme=None, cta_count=5):
16
+ if not product_service or not target_audience or not desired_action:
17
+ return "Por favor, completa todos los campos requeridos."
18
+
19
+ formula = cta_formulas[formula_type]
20
+ tone = tone_settings[tone_type]
21
+
22
+ # Preparar información de postdata si existe
23
+ postdata_instruction = ""
24
+ if postdata_theme:
25
+ postdata_instruction = f"""
26
+ POSTDATA THEME:
27
+ Include a P.S. (postdata) after each CTA focusing on: {postdata_theme}
28
+ The postdata should reinforce the main message and add an extra persuasion element.
29
+ """
30
+
31
+ model = genai.GenerativeModel('gemini-2.0-flash')
32
+ full_prompt = f"""
33
+ You are an expert copywriter specialized in creating persuasive Calls to Action (CTAs).
34
+ Analyze (internally, don't include in output) the following information:
35
+
36
+ BUSINESS INFORMATION:
37
+ Product/Service: {product_service}
38
+ Target Audience: {target_audience}
39
+ Desired Action: {desired_action}
40
+ CTA Type: {formula_type}
41
+ Tone Style: {tone['style']}
42
+ Keywords to consider: {', '.join(tone['keywords'])}
43
+ {formula["description"]}
44
+ {postdata_instruction}
45
+
46
+ EXAMPLES TO FOLLOW:
47
+ {formula["examples"]}
48
+
49
+ First, analyze (but don't show) these points:
50
+ 1. TARGET AUDIENCE ANALYSIS:
51
+ - What motivates them to take action?
52
+ - What obstacles prevent them from acting?
53
+ - What immediate benefits are they seeking?
54
+ - What fears or doubts do they have?
55
+ - What language and tone resonates with them?
56
+
57
+ 2. PERSUASION ELEMENTS:
58
+ - How to make the desired action more appealing?
59
+ - What emotional triggers will resonate most?
60
+ - How to create a sense of urgency naturally?
61
+ - What unique value proposition to emphasize?
62
+ - How to minimize perceived risk?
63
+
64
+ Based on your internal analysis, create {cta_count} different CTAs following EXACTLY the formula structure:
65
+ {formula["description"]}
66
+
67
+ CRITICAL INSTRUCTIONS:
68
+ - Follow the exact formula structure shown in the description above
69
+ - Create {cta_count} different CTAs using the same formula pattern
70
+ - ALL CTAs MUST BE IN SPANISH
71
+ {postdata_instruction}
72
+
73
+ Use these examples as reference for the formula structure:
74
+ {formula["examples"]}
75
+ Output EXACTLY in this format based on {formula_type}:
76
+ 1. Follow format from {formula["examples"]}
77
+
78
+ 2. Follow format from {formula["examples"]}
79
+
80
+ 3. Follow format from {formula["examples"]}
81
+ """
82
+
83
+ response = model.generate_content([full_prompt], generation_config={"temperature": temperature})
84
+ return response.parts[0].text if response and response.parts else "Error al generar contenido."
85
+
86
+ # Configurar la aplicación Streamlit
87
+ st.set_page_config(page_title="CTA Generator", page_icon="🎯", layout="wide")
88
+
89
+ # Leer y mostrar el manual en el sidebar
90
+ with open("manual.md", "r", encoding="utf-8") as file:
91
+ manual_content = file.read()
92
+ st.sidebar.markdown(manual_content)
93
+
94
+ # Aplicar estilos
95
+ st.markdown(apply_styles(), unsafe_allow_html=True)
96
+
97
+ # Título de la app
98
+ st.markdown("<h1>Generador de CTAs Persuasivos</h1>", unsafe_allow_html=True)
99
+ st.markdown("<h3>Crea llamados a la acción que motiven a tu audiencia a dar el siguiente paso.</h3>", unsafe_allow_html=True)
100
+
101
+ # Remove the duplicate manual expander from here
102
+
103
+ # Crear dos columnas
104
+ col1, col2 = st.columns([0.4, 0.6]) # 40% for left column, 60% for right column
105
+
106
+ # Columna izquierda para inputs
107
+ with col1:
108
+ target_audience = st.text_area(
109
+ "¿Cuál es tu público objetivo?",
110
+ placeholder="Ejemplo: Emprendedores que buscan automatizar su negocio..."
111
+ )
112
+
113
+ product_service = st.text_area(
114
+ "¿Cuál es tu producto o servicio?",
115
+ placeholder="Ejemplo: Curso de automatización con IA, Software de gestión..."
116
+ )
117
+
118
+ desired_action = st.text_area(
119
+ "¿Qué acción quieres que realicen?",
120
+ placeholder="Ejemplo: Registrarse al webinar, Descargar la guía gratuita..."
121
+ )
122
+
123
+ with st.expander("Opciones avanzadas"):
124
+ formula_type = st.selectbox(
125
+ "Tipo de CTA:",
126
+ options=list(cta_formulas.keys())
127
+ )
128
+
129
+ tone_type = st.selectbox(
130
+ "Tono del CTA:",
131
+ options=list(tone_settings.keys()),
132
+ )
133
+
134
+ # Nuevos campos para postdata
135
+ postdata_theme = st.text_input(
136
+ "Tema o enfoque para la postdata",
137
+ placeholder="Ejemplo: urgencia, beneficio, descuento"
138
+ )
139
+
140
+ cta_count = st.number_input(
141
+ "Número de llamados a la acción",
142
+ min_value=1,
143
+ max_value=5,
144
+ value=3
145
+ )
146
+
147
+ temperature = st.slider(
148
+ "Nivel de creatividad:",
149
+ min_value=0.0,
150
+ max_value=2.0,
151
+ value=1.0,
152
+ step=0.1,
153
+ help="Valores más altos generan CTAs más creativos pero menos predecibles."
154
+ )
155
+
156
+ generate_button = st.button("Generar CTAs")
157
+
158
+ # Columna derecha para resultados
159
+ with col2:
160
+ if generate_button and (response := get_gemini_response(
161
+ product_service,
162
+ target_audience,
163
+ desired_action,
164
+ formula_type,
165
+ tone_type,
166
+ temperature,
167
+ postdata_theme,
168
+ cta_count
169
+ )):
170
+ st.markdown("### Tus Llamados a la Acción")
171
  st.write(response)