Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
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]
|
| 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 |
-
- What
|
| 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 |
-
st.
|
| 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 |
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)
|