File size: 7,199 Bytes
91a0d7e a8fd769 d51e47b a8fd769 d51e47b de356ae 522d135 de356ae 522d135 063a515 de356ae 522d135 de356ae 7545fe6 de356ae 7545fe6 de356ae 7545fe6 de356ae 6333949 de356ae a8fd769 de356ae d51e47b 1ff0df4 522d135 d51e47b ae4c2eb bef3dc5 070b033 85052d2 34cb5f8 a8fd769 1da5874 34cb5f8 4e62a59 60ce54c 34cb5f8 1da5874 34cb5f8 85052d2 34cb5f8 85052d2 34cb5f8 85052d2 34cb5f8 85052d2 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 |
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, 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.
FORMAT RULES:
- Each headline must start with number and period
- One headline per line
- No explanations or categories
- Add a line break between each headline
- Avoid unnecessary : symbols
- Each headline must be a complete and intriguing sentence
IMPORTANT ANGLE INSTRUCTIONS:
- The selected angle MUST be applied to EVERY headline
- The angle modifies HOW the formula is expressed, not its structure
- Think of the angle as a "tone overlay" on the formula
- The formula provides the structure, the angle provides the style
- Both must work together seamlessly
FORMAT EXAMPLE:
1. Titular 1.
2. Titular 2.
3. Titular 3.
4. Titular 4.
5. Titular 5.
IMPORTANT:
- Each headline must be unique and memorable
- Avoid clich茅s and generalities
- Maintain an intriguing but credible tone
- Adapt speaking language from the audience
- Focus on transformative benefits
- Follow the selected angle style while maintaining formula structure"""
story_formulas = {
"PASA": {
"description": """
La f贸rmula P.A.S.A. se estructura de manera natural y fluida:
1. **Problema**:
- Identificaci贸n del dolor espec铆fico
- Situaci贸n actual problem谩tica
- Frustraci贸n principal
2. **Agitaci贸n**:
- Consecuencias emocionales
- Impacto en la vida diaria
- Costos de no resolver
3. **Soluci贸n**:
- Presentaci贸n del producto/servicio
- Beneficios clave
- Transformaci贸n posible
4. **Acci贸n**:
- Siguiente paso claro
- Motivaci贸n para actuar
- Beneficio inmediato
"""
},
"ADP": {
"description": """
La f贸rmula A.D.P. fluye naturalmente:
1. **Antes**:
- Estado actual
- Frustraciones diarias
- Situaci贸n problem谩tica
2. **Despu茅s**:
- Escenario ideal
- Beneficios alcanzados
- Nueva realidad
3. **Puente**:
- Conexi贸n soluci贸n-resultado
- Transformaci贸n posible
- Camino al cambio
"""
},
"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, **kwargs):
"""Funci贸n unificada para generar historias"""
model = genai.GenerativeModel("gemini-1.5-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 {kwargs['length']} palabras con un tono {kwargs['mood']}, siguiendo la estructura:
{formula_description}
P煤blico objetivo: {kwargs['target_audience']}
Producto/Servicio: {kwargs['product']}
Llamada a acci贸n: {kwargs['action']}
"""
if formula_type == "GHA" and 'story_topic' in kwargs:
prompt += f"\nTema de la historia: {kwargs['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")
# 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 = get_pasa_response(target_audience, product, action, mood, length)
elif formula == "A.D.P.":
response = get_adp_response(target_audience, product, action, mood, length)
elif formula == "G.H.A.":
if story_topic:
response = get_gha_response(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).")
|