Spaces:
Build error
Build error
from dotenv import load_dotenv | |
import streamlit as st | |
import os | |
import google.generativeai as genai | |
from cta_formulas import cta_formulas | |
from styles import apply_styles | |
# Cargar variables de entorno | |
load_dotenv() | |
# Configurar API de Google Gemini | |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) | |
def get_gemini_response(product_service, target_audience, desired_action, formula_type, temperature): | |
if not product_service or not target_audience or not desired_action: | |
return "Por favor, completa todos los campos requeridos." | |
formula = cta_formulas[formula_type] | |
model = genai.GenerativeModel('gemini-2.0-flash') | |
full_prompt = f""" | |
You are an expert copywriter specialized in creating persuasive Calls to Action (CTAs). | |
Analyze (internally, don't include in output) the following information: | |
BUSINESS INFORMATION: | |
Product/Service: {product_service} | |
Target Audience: {target_audience} | |
Desired Action: {desired_action} | |
CTA Type: {formula_type} | |
{formula["description"]} | |
EXAMPLES TO FOLLOW: | |
{formula["examples"]} | |
First, analyze (but don't show) these points: | |
1. TARGET AUDIENCE ANALYSIS: | |
- What motivates them to take action? | |
- What obstacles prevent them from acting? | |
- What immediate benefits are they seeking? | |
- What fears or doubts do they have? | |
- What language and tone resonates with them? | |
2. PERSUASION ELEMENTS: | |
- How to make the desired action more appealing? | |
- What emotional triggers will resonate most? | |
- How to create a sense of urgency naturally? | |
- What unique value proposition to emphasize? | |
- How to minimize perceived risk? | |
Based on your internal analysis, create FIVE different CTAs following EXACTLY the formula structure: | |
{formula["description"]} | |
CRITICAL INSTRUCTIONS: | |
- Follow the exact formula structure shown in the description above | |
- Create FIVE different CTAs using the same formula pattern | |
- ALL CTAs MUST BE IN SPANISH | |
Use these examples as reference for the formula structure: | |
{formula["examples"]} | |
Output EXACTLY in this format based on {formula_type}: | |
1. Follow format from {formula["examples"]} | |
2. Follow format from {formula["examples"]} | |
3. Follow format from {formula["examples"]} | |
""" | |
response = model.generate_content([full_prompt], generation_config={"temperature": temperature}) | |
return response.parts[0].text if response and response.parts else "Error al generar contenido." | |
# Configurar la aplicación Streamlit | |
st.set_page_config(page_title="CTA Generator", page_icon="🎯", layout="wide") | |
# Aplicar estilos | |
st.markdown(apply_styles(), unsafe_allow_html=True) | |
# Título de la app | |
st.markdown("<h1>Generador de CTAs Persuasivos</h1>", unsafe_allow_html=True) | |
st.markdown("<h3>Crea llamados a la acción que motiven a tu audiencia a dar el siguiente paso.</h3>", unsafe_allow_html=True) | |
# Crear dos columnas | |
col1, col2 = st.columns([1, 1]) | |
# Columna izquierda para inputs | |
with col1: | |
target_audience = st.text_area( | |
"¿Cuál es tu público objetivo?", | |
placeholder="Ejemplo: Emprendedores que buscan automatizar su negocio..." | |
) | |
product_service = st.text_area( | |
"¿Cuál es tu producto o servicio?", | |
placeholder="Ejemplo: Curso de automatización con IA, Software de gestión..." | |
) | |
desired_action = st.text_area( | |
"¿Qué acción quieres que realicen?", | |
placeholder="Ejemplo: Registrarse al webinar, Descargar la guía gratuita..." | |
) | |
with st.expander("Opciones avanzadas"): | |
formula_type = st.selectbox( | |
"Tipo de CTA:", | |
options=list(cta_formulas.keys()) | |
) | |
temperature = st.slider( | |
"Nivel de creatividad:", | |
min_value=0.0, | |
max_value=2.0, | |
value=1.0, | |
step=0.1, | |
help="Valores más altos generan CTAs más creativos pero menos predecibles." | |
) | |
generate_button = st.button("Generar CTAs") | |
# Columna derecha para resultados | |
with col2: | |
if generate_button and (response := get_gemini_response( | |
product_service, | |
target_audience, | |
desired_action, | |
formula_type, | |
temperature | |
)): | |
st.markdown("### Tus Llamados a la Acción") | |
st.write(response) |