QuickBullets / app.py
JeCabrera's picture
Update app.py
346ec34 verified
raw
history blame
8.5 kB
from dotenv import load_dotenv
import streamlit as st
import os
import google.generativeai as genai
import random
# Cargar las variables de entorno
load_dotenv()
# Configurar la API de Google
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# Funci贸n para obtener una menci贸n del producto de manera probabil铆stica
def get_random_product_mention():
mentions = ["Directa", "Indirecta", "Metaf贸rica"]
probabilities = [0.34, 0.33, 0.33]
return random.choices(mentions, probabilities)[0]
# Crear la instrucci贸n de menci贸n basada en la opci贸n seleccionada
def get_mention_instruction(product_mention, product):
if product_mention == "Directa":
return f"""
Directly introduce the product '{product}' as the clear solution to the problem the reader is facing. Ensure that the product is presented in a way that highlights its key benefits and demonstrates how it directly addresses the issue at hand. The mention should feel natural and seamlessly integrated into the narrative.
"""
elif product_mention == "Indirecta":
return f"""
Subtly reference the product '{product}' as a potential solution to the reader's problem without naming it explicitly. Weave the product's core benefits into the description of how the reader can overcome the issue, creating an implicit connection between the solution and the product. Ensure the mention is subtle but clear enough to guide the reader towards the product.
"""
elif product_mention == "Metaf贸rica":
return f"""
Introduce the product '{product}' using a metaphor, connecting it symbolically to the solution the reader needs. The metaphor should relate to the problem being discussed and should creatively suggest how the product offers a resolution without explicitly stating its name. The metaphor should evoke the benefits of the product in a memorable and thought-provoking way.
"""
return ""
# System Prompt - Instrucci贸n en ingl茅s para el modelo
system_instruction = """
You are a world-class copywriter, expert in creating benefits that connect symptoms with problems. You deeply understand the emotions, desires, and challenges of a specific audience, allowing you to design personalized marketing 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.
Generate unusual, creative, and fascinating bullets that capture readers' attention about the product. Respond in Spanish and use a numbered list format. Important: Only answer bullets, 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 cursioso).'.
"""
# Funci贸n para obtener una cantidad de bullets
def get_gemini_response_bullets(target_audience, product, num_bullets, creativity):
product_mention = get_random_product_mention()
mention_instruction = get_mention_instruction(product_mention, product) # Define aqu铆
model_choice = "gemini-1.5-flash" # Modelo por defecto
model = genai.GenerativeModel(model_choice)
# System Prompt - Instrucci贸n en ingl茅s para el modelo
system_instruction = """
You are a world-class copywriter, expert in creating benefits that connect symptoms with problems. You deeply understand the emotions, desires, and challenges of a specific audience, allowing you to design personalized marketing 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.
Generate unusual, creative, and fascinating bullets that subtly hint at the product without direct mention, capturing readers' attention. Respond in Spanish and use a numbered list format. Important: 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.'.
"""
# Crear el prompt para generar bullets
full_prompt = f"""
{system_instruction}
Your task is to create {num_bullets} benefits or bullets that connect the symptom with the problem faced by {target_audience}, increasing their desire to acquire the {product}.
Infuse your responses with a creativity level of {creativity}. The bullets should be of the following types:
* 'The bathroom cabinet is the best place to store medicine, right? Incorrect. It's the worst. The facts are on page 10.'
* 'The best verb tense that gives your clients the feeling they've already bought from you.'
* 'The story of...', 'The mysteries of...', 'The legend of...'
* 'A simple system to write copy without trying to convince them to buy.'
* Truth: 'The truth that you've never been told in school, or at home, about how to make a living from music.'
* 'Did you know that...'
* 'When is it a good idea to tell a girl you like her? If you don't say it at that moment, say goodbye to getting to know her intimately.'
Using {mention_instruction} when you want to mention {product}.
Use the following mention instructions to guide your writing: {mention_instruction}
Using the mention type '{product_mention}' to guide how to mention the product in the benefits or bullets. Ensure the mention is adapted based on this type:
- Direct: Clearly highlight the product as the solution.
- Indirect: Subtly suggest the product without naming it.
- Metaphorical: Use a metaphor to connect the product to the solution.
When responding, always include a headline that references the {target_audience} and the product in the following way: 'Aqu铆 tienes 5 bullets para Pap谩s solteros, que aumenten el deseo de adquirir el Aceite multigrado, usando la menci贸n indirecta:'
Please create the bullets now.
"""
response = model.generate_content([full_prompt])
if response and response.parts:
return response.parts[0].text
else:
raise ValueError("Lo sentimos, intenta con una combinaci贸n diferente de entradas.")
# Inicializar la aplicaci贸n Streamlit
st.set_page_config(page_title="Generador de Bullets", layout="wide")
# Centrar el t铆tulo y el subt铆tulo
st.markdown("<h1 style='text-align: center;'>Impact Bullet Generator</h1>", unsafe_allow_html=True)
st.markdown("<h4 style='text-align: center;'>Transforma los pensamientos de tu audiencia en balas persuasivas que inspiren a la acci贸n.</h4>", unsafe_allow_html=True)
# A帽adir CSS personalizado para el bot贸n
st.markdown("""
<style>
div.stButton > button {
background-color: #FFCC00;
color: black;
width: 90%;
height: 60px;
font-weight: bold;
font-size: 22px;
text-transform: uppercase;
border: 1px solid #000000;
border-radius: 8px;
display: block;
margin: 0 auto;
}
div.stButton > button:hover {
background-color: #FFD700;
color: black;
}
</style>
""", unsafe_allow_html=True)
# Crear dos columnas para el layout (40% y 60%)
col1, col2 = st.columns([2, 3])
with col1:
# Campos de entrada
target_audience = st.text_input("驴Qui茅n es tu p煤blico objetivo?")
product = st.text_input("驴Qu茅 producto tienes en mente?")
# Campos de personalizaci贸n sin acorde贸n
num_bullets = st.slider("N煤mero de Bullets", min_value=1, max_value=15, value=5)
creativity = st.selectbox("Creatividad", ["Alta", "Media", "Baja"])
# Bot贸n de enviar
submit = st.button("Generar Bullets")
# Mostrar los bullets generados
if submit:
if target_audience and product:
try:
# Obtener la respuesta del modelo
generated_bullets = get_gemini_response_bullets(target_audience, product, num_bullets, creativity)
col2.markdown(f"""
<div style="border: 1px solid #000000; padding: 5px; border-radius: 8px; background-color: #ffffff;">
<h4>Observa la magia en acci贸n:</h4>
<p>{generated_bullets}</p>
</div>
""", unsafe_allow_html=True)
except ValueError as e:
col2.error(f"Error: {str(e)}")
else:
col2.error("Por favor, proporciona el p煤blico objetivo y el producto.")