Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# Código
|
2 |
|
3 |
from dotenv import load_dotenv
|
4 |
import streamlit as st
|
@@ -15,7 +15,7 @@ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
15 |
# Función para obtener una mención del producto de manera probabilística
|
16 |
def get_random_product_mention():
|
17 |
mentions = ["Directa", "Indirecta", "Metafórica"]
|
18 |
-
probabilities = [0.34, 0.33, 0.33]
|
19 |
return random.choices(mentions, probabilities)[0]
|
20 |
|
21 |
# Crear la instrucción de mención basada en la opción seleccionada
|
@@ -29,7 +29,6 @@ def get_mention_instruction(product_mention, product):
|
|
29 |
return ""
|
30 |
|
31 |
# Ejemplos de titulares por tipo
|
32 |
-
|
33 |
headline_types = {
|
34 |
"pregunta": [
|
35 |
"¿Qué sorprendente secreto revela el éxito detrás de los grandes emprendedores?",
|
@@ -78,44 +77,44 @@ headline_types = {
|
|
78 |
}
|
79 |
|
80 |
# Función para generar titulares
|
81 |
-
def generate_headlines(number_of_headlines, target_audience, product, temperature):
|
82 |
product_mention = get_random_product_mention()
|
83 |
mention_instruction = get_mention_instruction(product_mention, product)
|
84 |
|
85 |
# Crear la configuración del modelo
|
86 |
generation_config = {
|
87 |
"temperature": temperature,
|
88 |
-
"top_p": 0.85,
|
89 |
-
"top_k": 128,
|
90 |
-
"max_output_tokens": 2048,
|
91 |
"response_mime_type": "text/plain",
|
92 |
-
}
|
93 |
|
94 |
model = genai.GenerativeModel(
|
95 |
model_name="gemini-1.5-flash",
|
96 |
generation_config=generation_config,
|
97 |
-
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
|
98 |
)
|
99 |
|
100 |
-
# Crear un mensaje para el modelo que incluye tipos específicos
|
101 |
-
selected_types = random.sample(
|
102 |
headlines_instruction = (
|
103 |
f"Tu tarea es crear {number_of_headlines} ganchos o encabezados titulares llamativos diseñados para {target_audience} "
|
104 |
f"con el fin de generar interés en {product}. Usa la siguiente mención: {mention_instruction}. "
|
105 |
-
"Asegúrate de utilizar
|
106 |
)
|
107 |
|
108 |
chat_session = model.start_chat(
|
109 |
history=[
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
]
|
115 |
)
|
116 |
|
117 |
-
response = chat_session.send_message("Genera los titulares")
|
118 |
-
return response.text
|
119 |
|
120 |
# Configurar la interfaz de usuario con Streamlit
|
121 |
st.set_page_config(page_title="Enchanted Hooks", layout="wide")
|
@@ -148,7 +147,7 @@ st.markdown("""
|
|
148 |
""", unsafe_allow_html=True)
|
149 |
|
150 |
# Crear columnas
|
151 |
-
col1, col2 = st.columns([1, 2])
|
152 |
|
153 |
# Columnas de entrada
|
154 |
with col1:
|
@@ -156,9 +155,14 @@ with col1:
|
|
156 |
product = st.text_input("¿Qué producto tienes en mente?", placeholder="Ejemplo: Curso de Inglés")
|
157 |
number_of_headlines = st.selectbox("Número de Titulares", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=4)
|
158 |
|
159 |
-
# Crear acordión para la creatividad
|
160 |
with st.expander("Personaliza tus titulares"):
|
161 |
temperature = st.slider("Creatividad", min_value=0.0, max_value=1.0, value=0.5, step=0.1)
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
# Botón de enviar
|
164 |
submit = st.button("Generar Titulares")
|
@@ -168,7 +172,9 @@ if submit:
|
|
168 |
if target_audience and product:
|
169 |
try:
|
170 |
# Obtener la respuesta del modelo
|
171 |
-
generated_headlines = generate_headlines(
|
|
|
|
|
172 |
col2.markdown(f"""
|
173 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
174 |
<h4>Observa la magia en acción:</h4>
|
|
|
1 |
+
# Código actualizado con selección de tipos de encabezados
|
2 |
|
3 |
from dotenv import load_dotenv
|
4 |
import streamlit as st
|
|
|
15 |
# Función para obtener una mención del producto de manera probabilística
|
16 |
def get_random_product_mention():
|
17 |
mentions = ["Directa", "Indirecta", "Metafórica"]
|
18 |
+
probabilities = [0.34, 0.33, 0.33]
|
19 |
return random.choices(mentions, probabilities)[0]
|
20 |
|
21 |
# Crear la instrucción de mención basada en la opción seleccionada
|
|
|
29 |
return ""
|
30 |
|
31 |
# Ejemplos de titulares por tipo
|
|
|
32 |
headline_types = {
|
33 |
"pregunta": [
|
34 |
"¿Qué sorprendente secreto revela el éxito detrás de los grandes emprendedores?",
|
|
|
77 |
}
|
78 |
|
79 |
# Función para generar titulares
|
80 |
+
def generate_headlines(number_of_headlines, target_audience, product, temperature, selected_types):
|
81 |
product_mention = get_random_product_mention()
|
82 |
mention_instruction = get_mention_instruction(product_mention, product)
|
83 |
|
84 |
# Crear la configuración del modelo
|
85 |
generation_config = {
|
86 |
"temperature": temperature,
|
87 |
+
"top_p": 0.85,
|
88 |
+
"top_k": 128,
|
89 |
+
"max_output_tokens": 2048,
|
90 |
"response_mime_type": "text/plain",
|
91 |
+
}
|
92 |
|
93 |
model = genai.GenerativeModel(
|
94 |
model_name="gemini-1.5-flash",
|
95 |
generation_config=generation_config,
|
96 |
+
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.",
|
97 |
)
|
98 |
|
99 |
+
# Crear un mensaje para el modelo que incluye tipos específicos
|
100 |
+
selected_types = random.sample(selected_types, min(number_of_headlines, len(selected_types)))
|
101 |
headlines_instruction = (
|
102 |
f"Tu tarea es crear {number_of_headlines} ganchos o encabezados titulares llamativos diseñados para {target_audience} "
|
103 |
f"con el fin de generar interés en {product}. Usa la siguiente mención: {mention_instruction}. "
|
104 |
+
"Asegúrate de utilizar los siguientes tipos de titulares: " + ", ".join(selected_types) + "."
|
105 |
)
|
106 |
|
107 |
chat_session = model.start_chat(
|
108 |
history=[
|
109 |
+
{
|
110 |
+
"role": "user",
|
111 |
+
"parts": [headlines_instruction],
|
112 |
+
},
|
113 |
]
|
114 |
)
|
115 |
|
116 |
+
response = chat_session.send_message("Genera los titulares")
|
117 |
+
return response.text
|
118 |
|
119 |
# Configurar la interfaz de usuario con Streamlit
|
120 |
st.set_page_config(page_title="Enchanted Hooks", layout="wide")
|
|
|
147 |
""", unsafe_allow_html=True)
|
148 |
|
149 |
# Crear columnas
|
150 |
+
col1, col2 = st.columns([1, 2])
|
151 |
|
152 |
# Columnas de entrada
|
153 |
with col1:
|
|
|
155 |
product = st.text_input("¿Qué producto tienes en mente?", placeholder="Ejemplo: Curso de Inglés")
|
156 |
number_of_headlines = st.selectbox("Número de Titulares", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=4)
|
157 |
|
158 |
+
# Crear acordión para la creatividad y selección de tipos
|
159 |
with st.expander("Personaliza tus titulares"):
|
160 |
temperature = st.slider("Creatividad", min_value=0.0, max_value=1.0, value=0.5, step=0.1)
|
161 |
+
selected_headline_types = st.multiselect(
|
162 |
+
"Selecciona los tipos de encabezados que deseas generar:",
|
163 |
+
options=list(headline_types.keys()),
|
164 |
+
default=list(headline_types.keys())
|
165 |
+
)
|
166 |
|
167 |
# Botón de enviar
|
168 |
submit = st.button("Generar Titulares")
|
|
|
172 |
if target_audience and product:
|
173 |
try:
|
174 |
# Obtener la respuesta del modelo
|
175 |
+
generated_headlines = generate_headlines(
|
176 |
+
number_of_headlines, target_audience, product, temperature, selected_headline_types
|
177 |
+
)
|
178 |
col2.markdown(f"""
|
179 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
180 |
<h4>Observa la magia en acción:</h4>
|