Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,13 +7,13 @@ import random
|
|
| 7 |
# Cargar las variables de entorno
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
-
# Configurar la API de
|
| 11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 12 |
|
| 13 |
# Funci贸n para obtener una menci贸n del producto de manera probabil铆stica
|
| 14 |
def get_random_product_mention():
|
| 15 |
mentions = ["Indirecta", "Metaf贸rica"]
|
| 16 |
-
probabilities = [0.50, 0.50]
|
| 17 |
return random.choices(mentions, probabilities)[0]
|
| 18 |
|
| 19 |
# Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
|
|
@@ -24,101 +24,166 @@ def get_mention_instruction(product_mention, product):
|
|
| 24 |
return f"Introduce el producto '{product}' usando una met谩fora, conect谩ndolo simb贸licamente a la soluci贸n que necesita el lector."
|
| 25 |
return ""
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
product_mention = get_random_product_mention()
|
| 30 |
mention_instruction = get_mention_instruction(product_mention, product)
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
"
|
| 35 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
""
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
target_audience=target_audience,
|
| 53 |
-
mention_instruction=mention_instruction
|
| 54 |
-
) + f"\n\nEnfoque: {point}\n"
|
| 55 |
-
|
| 56 |
-
# Configuraci贸n del modelo y generaci贸n de contenido
|
| 57 |
-
response = genai.generate_text(
|
| 58 |
-
model="gemini-1.5-flash",
|
| 59 |
-
prompt=specific_prompt,
|
| 60 |
-
temperature=creativity,
|
| 61 |
-
top_p=0.65,
|
| 62 |
-
top_k=280,
|
| 63 |
-
max_output_tokens=2048,
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
if response and response.generations:
|
| 67 |
-
bullet = response.generations[0].text.strip()
|
| 68 |
-
benefits.append(bullet)
|
| 69 |
-
else:
|
| 70 |
-
benefits.append("No se pudo generar un beneficio para este enfoque.")
|
| 71 |
-
|
| 72 |
-
return benefits
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
#
|
| 78 |
-
|
| 79 |
-
manual_content = file.read()
|
| 80 |
|
| 81 |
-
#
|
| 82 |
-
st.
|
| 83 |
|
| 84 |
# Centrar el t铆tulo y el subt铆tulo
|
| 85 |
-
st.markdown("<h1 style='text-align: center;'>
|
| 86 |
-
st.markdown("<h4 style='text-align: center;'>Transforma
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# Crear columnas
|
| 89 |
-
col1, col2 = st.columns([1, 2])
|
| 90 |
|
| 91 |
# Columnas de entrada
|
| 92 |
with col1:
|
| 93 |
-
target_audience = st.text_input("
|
| 94 |
-
product = st.text_input("
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
)
|
| 107 |
|
|
|
|
| 108 |
submit = st.button("Generar Beneficios")
|
| 109 |
|
| 110 |
# Mostrar los beneficios generados
|
| 111 |
-
|
| 112 |
-
if
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
st.markdown(f"""
|
| 118 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
| 119 |
-
<h4>
|
| 120 |
-
<p
|
| 121 |
</div>
|
| 122 |
""", unsafe_allow_html=True)
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
| 7 |
# Cargar las variables de entorno
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
+
# Configurar la API de Google
|
| 11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 12 |
|
| 13 |
# Funci贸n para obtener una menci贸n del producto de manera probabil铆stica
|
| 14 |
def get_random_product_mention():
|
| 15 |
mentions = ["Indirecta", "Metaf贸rica"]
|
| 16 |
+
probabilities = [0.50, 0.50]
|
| 17 |
return random.choices(mentions, probabilities)[0]
|
| 18 |
|
| 19 |
# Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
|
|
|
|
| 24 |
return f"Introduce el producto '{product}' usando una met谩fora, conect谩ndolo simb贸licamente a la soluci贸n que necesita el lector."
|
| 25 |
return ""
|
| 26 |
|
| 27 |
+
# F贸rmulas con ejemplos y explicaciones
|
| 28 |
+
benefits_formulas = {
|
| 29 |
+
"plantilla": {
|
| 30 |
+
"description": """
|
| 31 |
+
Crea bullets de beneficios que respondan estas tres preguntas clave:
|
| 32 |
+
1. 驴Qu茅 es lo que el lector quiere conseguir?
|
| 33 |
+
2. 驴En qu茅 periodo de tiempo quiere conseguirlo?
|
| 34 |
+
3. 驴Cu谩l es la objeci贸n principal del lector que le impide lograrlo?
|
| 35 |
+
""",
|
| 36 |
+
"examples": [
|
| 37 |
+
"Obt茅n tus primeros 100 clientes en 30 d铆as, sin gastar un solo centavo en publicidad.",
|
| 38 |
+
"Pierde esos 5 kilos en solo 10 minutos al d铆a, sin dejar de disfrutar tus comidas favoritas.",
|
| 39 |
+
"Ahorra para salir de viaje en tres meses, sin sacrificar esas noches de cine."
|
| 40 |
+
]
|
| 41 |
+
},
|
| 42 |
+
"formula_suprema_istvanova": {
|
| 43 |
+
"description": """
|
| 44 |
+
La f贸rmula Suprema de Istvanova: N煤meros + Adjetivo + Palabra Clave + Raz贸n + Promesa.
|
| 45 |
+
Dise帽ada para crear beneficios espec铆ficos y atractivos que conecten emocionalmente con tu audiencia. Cada elemento cumple una funci贸n clave:
|
| 46 |
+
1. **N煤meros**: Establecen una expectativa clara y medible.
|
| 47 |
+
2. **Adjetivo**: A帽aden emoci贸n y atractivo al mensaje.
|
| 48 |
+
3. **Palabra Clave**: Reflejan el beneficio principal o tema clave.
|
| 49 |
+
4. **Raz贸n**: Justifican el beneficio o valor del producto.
|
| 50 |
+
5. **Promesa**: Muestran el resultado o beneficio que el lector puede esperar.
|
| 51 |
+
""",
|
| 52 |
+
"examples": [
|
| 53 |
+
"5 m茅todos simples para duplicar tus ventas en menos de 30 d铆as.",
|
| 54 |
+
"8 trucos secretos para que tu perro obedezca en una semana.",
|
| 55 |
+
"10 t茅cnicas f谩ciles que mejorar谩n tu relaci贸n antes de un mes."
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
"formula_aida": {
|
| 59 |
+
"description": """
|
| 60 |
+
La f贸rmula AIDA para beneficios: Atenci贸n + Inter茅s + Deseo + Acci贸n.
|
| 61 |
+
Construye beneficios que sigan estos pasos:
|
| 62 |
+
- **Atenci贸n**: Captura de inmediato el inter茅s del lector.
|
| 63 |
+
- **Inter茅s**: Detalla c贸mo el beneficio soluciona un problema espec铆fico.
|
| 64 |
+
- **Deseo**: Despierta el anhelo por lograr el resultado prometido.
|
| 65 |
+
- **Acci贸n**: Inspira al lector a actuar para obtener el beneficio.
|
| 66 |
+
""",
|
| 67 |
+
"examples": [
|
| 68 |
+
"Descubre c贸mo atraer clientes autom谩ticamente, sin experiencia previa.",
|
| 69 |
+
"Imagina tener un cuerpo en forma disfrutando lo que te gusta comer.",
|
| 70 |
+
"Empieza hoy mismo y experimenta resultados en solo 7 d铆as."
|
| 71 |
+
]
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
# Funci贸n para generar bullets de beneficios
|
| 76 |
+
def generate_benefits(number_of_benefits, target_audience, product, temperature, selected_formula):
|
| 77 |
product_mention = get_random_product_mention()
|
| 78 |
mention_instruction = get_mention_instruction(product_mention, product)
|
| 79 |
|
| 80 |
+
# Crear la configuraci贸n del modelo
|
| 81 |
+
generation_config = {
|
| 82 |
+
"temperature": temperature,
|
| 83 |
+
"top_p": 0.65, # Considerar un poco menos de palabras probables
|
| 84 |
+
"top_k": 360, # Aumentar las palabras candidatas para m谩s variedad
|
| 85 |
+
"max_output_tokens": 8196, # Mantenerlo igual, pero puedes aumentar si deseas m谩s detalle
|
| 86 |
+
"response_mime_type": "text/plain",
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
model = genai.GenerativeModel(
|
| 90 |
+
model_name="gemini-1.5-flash",
|
| 91 |
+
generation_config=generation_config,
|
| 92 |
+
system_instruction="You are a world-class copywriter, with expertise in crafting benefits that connect emotionally and address the desires, problems, and motivations of a target audience. Your task is to generate compelling and specific benefit bullets in Spanish based on a given formula. Always respond with a numbered list format, and ensure each benefit is relevant, concise, and action-oriented. Do not include explanations or categories in your output."
|
| 93 |
)
|
| 94 |
|
| 95 |
+
# Crear un mensaje para el modelo, destacando la audiencia, el producto, la f贸rmula seleccionada y los ejemplos
|
| 96 |
+
benefits_instruction = (
|
| 97 |
+
f"Tu tarea es crear {number_of_benefits} beneficios espec铆ficos y atractivos dise帽ados para {target_audience}. "
|
| 98 |
+
f"El objetivo es conectar emocionalmente y destacar c贸mo {product} puede mejorar la vida del lector. Aseg煤rate de que cada beneficio sea "
|
| 99 |
+
f"llamativo, persuasivo y relevante, siguiendo la estructura de la f贸rmula seleccionada, que puedes ver a continuaci贸n: "
|
| 100 |
+
f"\n\n{selected_formula['description']}\n\n"
|
| 101 |
+
f"Revisa los siguientes ejemplos de c贸mo esta f贸rmula puede ser utilizada con 茅xito:\n"
|
| 102 |
+
f"- {selected_formula['examples'][0]}\n"
|
| 103 |
+
f"- {selected_formula['examples'][1]}\n"
|
| 104 |
+
f"- {selected_formula['examples'][2]}\n\n"
|
| 105 |
+
f"Usa estos ejemplos como inspiraci贸n y aseg煤rate de incluir la siguiente menci贸n en los beneficios generados: {mention_instruction}. "
|
| 106 |
+
f"No expliques las f贸rmulas ni la estructura en la salida, solo proporciona los beneficios. "
|
| 107 |
+
f"Recuerda, el objetivo es inspirar acci贸n y generar deseo en el lector."
|
| 108 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
chat_session = model.start_chat(
|
| 111 |
+
history=[
|
| 112 |
+
{
|
| 113 |
+
"role": "user",
|
| 114 |
+
"parts": [benefits_instruction],
|
| 115 |
+
},
|
| 116 |
+
]
|
| 117 |
+
)
|
| 118 |
|
| 119 |
+
response = chat_session.send_message("Genera los beneficios") # Enviar mensaje para obtener la respuesta
|
| 120 |
+
return response.text # Regresar la respuesta directamente
|
|
|
|
| 121 |
|
| 122 |
+
# Configurar la interfaz de usuario con Streamlit
|
| 123 |
+
st.set_page_config(page_title="Bullet Benefits Generator", layout="wide")
|
| 124 |
|
| 125 |
# Centrar el t铆tulo y el subt铆tulo
|
| 126 |
+
st.markdown("<h1 style='text-align: center;'>Bullet Benefits Generator</h1>", unsafe_allow_html=True)
|
| 127 |
+
st.markdown("<h4 style='text-align: center;'>Transforma caracter铆sticas en beneficios irresistibles que conectan emocionalmente con tu audiencia.</h4>", unsafe_allow_html=True)
|
| 128 |
+
|
| 129 |
+
# A帽adir CSS personalizado para el bot贸n
|
| 130 |
+
st.markdown("""
|
| 131 |
+
<style>
|
| 132 |
+
div.stButton > button {
|
| 133 |
+
background-color: #FFCC00;
|
| 134 |
+
color: black;
|
| 135 |
+
width: 90%;
|
| 136 |
+
height: 60px;
|
| 137 |
+
font-weight: bold;
|
| 138 |
+
font-size: 22px;
|
| 139 |
+
text-transform: uppercase;
|
| 140 |
+
border: 1px solid #000000;
|
| 141 |
+
border-radius: 8px;
|
| 142 |
+
display: block;
|
| 143 |
+
margin: 0 auto;
|
| 144 |
+
}
|
| 145 |
+
div.stButton > button:hover {
|
| 146 |
+
background-color: #FFD700;
|
| 147 |
+
color: black;
|
| 148 |
+
}
|
| 149 |
+
</style>
|
| 150 |
+
""", unsafe_allow_html=True)
|
| 151 |
|
| 152 |
# Crear columnas
|
| 153 |
+
col1, col2 = st.columns([1, 2])
|
| 154 |
|
| 155 |
# Columnas de entrada
|
| 156 |
with col1:
|
| 157 |
+
target_audience = st.text_input("驴Qui茅n es tu p煤blico objetivo?", placeholder="Ejemplo: Estudiantes Universitarios")
|
| 158 |
+
product = st.text_input("驴Qu茅 producto tienes en mente?", placeholder="Ejemplo: Curso de Ingl茅s")
|
| 159 |
+
number_of_benefits = st.selectbox("N煤mero de Beneficios", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=4)
|
| 160 |
+
|
| 161 |
+
# Crear un 煤nico acorde贸n para f贸rmula y creatividad
|
| 162 |
+
with st.expander("Personaliza tus beneficios"):
|
| 163 |
+
temperature = st.slider("Creatividad", min_value=0.0, max_value=1.0, value=0.5, step=0.1)
|
| 164 |
+
|
| 165 |
+
selected_formula_key = st.selectbox(
|
| 166 |
+
"Selecciona una f贸rmula para tus beneficios",
|
| 167 |
+
options=list(benefits_formulas.keys())
|
| 168 |
+
)
|
| 169 |
+
selected_formula = benefits_formulas[selected_formula_key]
|
|
|
|
| 170 |
|
| 171 |
+
# Bot贸n de enviar
|
| 172 |
submit = st.button("Generar Beneficios")
|
| 173 |
|
| 174 |
# Mostrar los beneficios generados
|
| 175 |
+
if submit:
|
| 176 |
+
if target_audience and product and selected_formula:
|
| 177 |
+
try:
|
| 178 |
+
# Obtener la respuesta del modelo
|
| 179 |
+
generated_benefits = generate_benefits(number_of_benefits, target_audience, product, temperature, selected_formula)
|
| 180 |
+
col2.markdown(f"""
|
|
|
|
| 181 |
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
|
| 182 |
+
<h4>Explora los beneficios generados:</h4>
|
| 183 |
+
<p>{generated_benefits}</p>
|
| 184 |
</div>
|
| 185 |
""", unsafe_allow_html=True)
|
| 186 |
+
except ValueError as e:
|
| 187 |
+
col2.error(f"Error: {str(e)}")
|
| 188 |
+
else:
|
| 189 |
+
col2.error("Por favor, proporciona el p煤blico objetivo, el producto y selecciona una f贸rmula.")
|