Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# Código actualizado con
|
2 |
|
3 |
from dotenv import load_dotenv
|
4 |
import streamlit as st
|
@@ -80,109 +80,124 @@ headline_formulas = {
|
|
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 |
-
"Para todas las mamás primerizas que no logran cambiar el pañal de su bebé con éxito... aquí te decimos cómo hacerlo en 3 pasos.",
|
118 |
-
"¿La menstruación frustró tus vacaciones de verano? 10 tips supereficaces para disfrutar de tus vacaciones aun esos días.",
|
119 |
-
"Para Todas Los Emprendedores Que Están Frustrados Por Sus Ventas"
|
120 |
-
]
|
121 |
-
},
|
122 |
-
"sensacionalista": {
|
123 |
-
"description": "La prensa amarilla los usa una y otra vez. Las revistas de chismes de la farándula también lo hacen.",
|
124 |
-
"examples": [
|
125 |
-
"ATERRADOR método que utiliza el ejército israelí que te hará perder 7 kilos en tan solo una semana.",
|
126 |
-
"¡Mandar nudes es lo de hoy! Peligroso pero efectivo método para ligar en las redes sociales.",
|
127 |
-
"¡Nunca antes visto! Asesino serial consigue abrir una canal en YouTube para dar clases de cocina.",
|
128 |
-
"La más reciente prueba de amor que está matando a los adolescentes."
|
129 |
-
]
|
130 |
-
},
|
131 |
-
"contraste": {
|
132 |
-
"description": "Moldea la percepción que tenemos de las cosas. Crea un cortocircuito en la mente de las personas.",
|
133 |
-
"examples": [
|
134 |
-
"¿Quieres una piel joven y tersa? Descubre los secretos de una mujer de 60 años para tener la piel de bebé",
|
135 |
-
"Descubre cómo el mal aliento me ayudó a enamorar a la mujer de mis sueños",
|
136 |
-
"Esta técnica de lectura rápida me ayudó a pasar mis exámenes sin tener que pasar meses estudiando.",
|
137 |
-
"¿La menstruación frustró tus vacaciones de verano? 10 tips súper eficaces para disfrutar de tus vacaciones aún esos días."
|
138 |
-
]
|
139 |
-
},
|
140 |
-
"hazte_una_pregunta": {
|
141 |
-
"description": "Preguntar sobre algo que le interesa, hace que se detengan y reflexionen.",
|
142 |
-
"examples": [
|
143 |
-
"¿Cuál De Estos Problemas De Salud Quieres Solucionar?",
|
144 |
-
"¿Te gustaría ser más persuasivo y convincente para vender más y mejor?",
|
145 |
-
"¿Quieres aprender un nuevo idioma en poco tiempo y de forma sencilla?",
|
146 |
-
"¿Cometes estos errores garrafales en tus textos digitales? Aquí te decimos 4 apps que te ayudarán a tener buena ortografía..."
|
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 |
-
st.
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Código actualizado con las modificaciones solicitadas para las fórmulas
|
2 |
|
3 |
from dotenv import load_dotenv
|
4 |
import streamlit as st
|
|
|
80 |
}
|
81 |
}
|
82 |
|
83 |
+
# Función para generar titulares
|
84 |
+
def generate_headlines(number_of_headlines, target_audience, product, temperature, selected_formula):
|
85 |
+
product_mention = get_random_product_mention()
|
86 |
+
mention_instruction = get_mention_instruction(product_mention, product)
|
87 |
+
|
88 |
+
# Crear la configuración del modelo
|
89 |
+
generation_config = {
|
90 |
+
"temperature": temperature,
|
91 |
+
"top_p": 0.85, # Considerar un poco menos de palabras probables
|
92 |
+
"top_k": 128, # Aumentar las palabras candidatas para más variedad
|
93 |
+
"max_output_tokens": 2048, # Mantenerlo igual, pero puedes aumentar si deseas más detalle
|
94 |
+
"response_mime_type": "text/plain",
|
95 |
+
}
|
96 |
+
|
97 |
+
model = genai.GenerativeModel(
|
98 |
+
model_name="gemini-1.5-flash",
|
99 |
+
generation_config=generation_config,
|
100 |
+
system_instruction="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. Your skill lies in deeply understanding the emotions, desires, and challenges of a specific audience. You are also an expert in creating benefits that connect symptoms with problems, allowing you to design personalized strategies that resonate and motivate action. You know how to use proven structures to attract your target audience, generating interest and creating a powerful connection. Your task is to generate unusual, creative, and fascinating subject lines or headlines that spark curiosity and encourage the reader to engage further. Respond in Spanish and use a numbered list format. Important: Only answer with subject lines, never include explanations or categories, like this: 'La leyenda del padre soltero: Dice que nunca hay tiempo suficiente. El yoga te enseña a usar mejor el tiempo que tienes, incluso cuando te parece imposible (este bullet es curioso).'"
|
101 |
+
)
|
102 |
+
|
103 |
+
# Crear un mensaje para el modelo que incluye tipos específicos, pero no los menciona en la salida
|
104 |
+
headlines_instruction = (
|
105 |
+
f"Tu tarea es crear {number_of_headlines} ganchos o encabezados titulares llamativos diseñados para {target_audience} "
|
106 |
+
f"con el fin de generar interés en {product}. Usa la siguiente mención: {mention_instruction}. "
|
107 |
+
f"Asegúrate de utilizar la fórmula de titular seleccionada: {selected_formula['description']}. "
|
108 |
+
f"Usa los ejemplos proporcionados para guiar tu creatividad."
|
109 |
+
)
|
110 |
+
|
111 |
+
chat_session = model.start_chat(
|
112 |
+
history=[
|
113 |
+
{
|
114 |
+
"role": "user",
|
115 |
+
"parts": [headlines_instruction],
|
116 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
]
|
118 |
+
)
|
119 |
+
|
120 |
+
response = chat_session.send_message("Genera los titulares") # Enviar mensaje para obtener la respuesta
|
121 |
+
return response.text # Regresar la respuesta directamente
|
122 |
+
|
123 |
+
# Configurar la interfaz de usuario con Streamlit
|
124 |
+
st.set_page_config(page_title="Enchanted Hooks", layout="wide")
|
125 |
+
|
126 |
+
# Centrar el título y el subtítulo
|
127 |
+
st.markdown("<h1 style='text-align: center;'>Enchanted Hooks</h1>", unsafe_allow_html=True)
|
128 |
+
st.markdown("<h4 style='text-align: center;'>Imagina poder conjurar títulos que no solo informan, sino que encantan. Esta app es tu varita mágica en el mundo del copywriting, transformando cada concepto en un titular cautivador que deja a todos deseando más.</h4>", unsafe_allow_html=True)
|
129 |
+
|
130 |
+
# Añadir CSS personalizado para el botón
|
131 |
+
st.markdown("""
|
132 |
+
<style>
|
133 |
+
div.stButton > button {
|
134 |
+
background-color: #FFCC00;
|
135 |
+
color: black;
|
136 |
+
width: 90%;
|
137 |
+
height: 60px;
|
138 |
+
font-weight: bold;
|
139 |
+
font-size: 22px;
|
140 |
+
text-transform: uppercase;
|
141 |
+
border: 1px solid #000000;
|
142 |
+
border-radius: 8px;
|
143 |
+
display: block;
|
144 |
+
margin: 0 auto;
|
145 |
}
|
146 |
+
div.stButton > button:hover {
|
147 |
+
background-color: #FFD700;
|
148 |
+
color: black;
|
149 |
+
}
|
150 |
+
</style>
|
151 |
+
""", unsafe_allow_html=True)
|
152 |
|
153 |
+
# Crear columnas
|
154 |
+
col1, col2 = st.columns([1, 2])
|
155 |
+
|
156 |
+
# Columnas de entrada
|
157 |
+
with col1:
|
158 |
+
target_audience = st.text_input("¿Quién es tu público objetivo?", placeholder="Ejemplo: Estudiantes Universitarios")
|
159 |
+
product = st.text_input("¿Qué producto tienes en mente?", placeholder="Ejemplo: Curso de Inglés")
|
160 |
+
number_of_headlines = st.selectbox("Número de Titulares", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=4)
|
161 |
+
|
162 |
+
# Crear un único acordeón para fórmula y creatividad
|
163 |
+
with st.expander("Personaliza tus titulares"):
|
164 |
+
temperature = st.slider("Creatividad", min_value=0.0, max_value=1.0, value=0.5, step=0.1)
|
165 |
+
|
166 |
+
selected_formula_key = st.selectbox(
|
167 |
+
"Selecciona una fórmula para tus titulares",
|
168 |
+
options=list(headline_formulas.keys())
|
169 |
+
)
|
170 |
+
selected_formula = headline_formulas[selected_formula_key]
|
171 |
+
|
172 |
+
# Mostrar ejemplos de la fórmula seleccionada
|
173 |
+
st.markdown(f"**Ejemplos de la fórmula seleccionada ({selected_formula_key}):**")
|
174 |
+
for example in selected_formula['examples']:
|
175 |
+
st.write(example)
|
176 |
+
|
177 |
+
if selected_formula_key == 'fórmula_3':
|
178 |
+
st.markdown(f"**Explicación de la fórmula AIDA:**")
|
179 |
+
st.markdown(selected_formula['explanation'])
|
180 |
+
elif selected_formula_key == 'fórmula_1':
|
181 |
+
st.markdown(f"**Preguntas clave para la fórmula 1:**")
|
182 |
+
for question in selected_formula['questions']:
|
183 |
+
st.write(question)
|
184 |
+
|
185 |
+
# Botón de enviar
|
186 |
+
submit = st.button("Generar Titulares")
|
187 |
+
|
188 |
+
# Mostrar los titulares generados
|
189 |
+
if submit:
|
190 |
+
if target_audience and product and selected_formula:
|
191 |
+
try:
|
192 |
+
# Obtener la respuesta del modelo
|
193 |
+
generated_headlines = generate_headlines(number_of_headlines, target_audience, product, temperature, selected_formula)
|
194 |
+
col2.markdown(f"""
|
195 |
+
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
196 |
+
<h4>Observa la magia en acción:</h4>
|
197 |
+
<p>{generated_headlines}</p>
|
198 |
+
</div>
|
199 |
+
""", unsafe_allow_html=True)
|
200 |
+
except ValueError as e:
|
201 |
+
col2.error(f"Error: {str(e)}")
|
202 |
+
else:
|
203 |
+
col2.error("Por favor, proporciona el público objetivo, el producto y selecciona una fórmula.")
|