QuickBullets / app.py
JeCabrera's picture
Update app.py
ad8bd78 verified
raw
history blame
4.68 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]
# System Prompt - Instrucci贸n en ingl茅s para el modelo
system_instruction = """
You are a world-class copywriter with expertise in creating benefits that connect symptoms to problems. Your skill lies in deeply understanding 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 that drives desired results in advertising and content campaigns. Respond in Spanish, using numbered lists. Create unusual, creative, and fascinating bullets that capture readers' attention. Do not mention the product directly in the benefits or bullets.
"""
# 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()
model_choice = "gemini-1.5-flash" # Modelo por defecto
model = genai.GenerativeModel(model_choice)
# Crear el prompt para generar bullets con la instrucci贸n del sistema
full_prompt = f"""
{system_instruction}
Audience: {target_audience}
Product: {product}
Number of bullets: {num_bullets}
Creativity: {creativity}
Use {product_mention} mention.
"""
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")
# Inicializar el estado de la expansi贸n del acorde贸n
if "accordion_expanded" not in st.session_state:
st.session_state["accordion_expanded"] = False
def toggle_accordion():
st.session_state["accordion_expanded"] = not st.session_state["accordion_expanded"]
# Centrar el t铆tulo y el subt铆tulo
st.markdown("<h1 style='text-align: center;'>Generador de Bullets</h1>", unsafe_allow_html=True)
st.markdown("<h4 style='text-align: center;'>Crea bullets efectivos que conecten emocionalmente con tu audiencia.</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?")
# Acorde贸n para personalizar los bullets
with st.expander("Personaliza tus bullets", expanded=st.session_state["accordion_expanded"]):
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", on_click=toggle_accordion)
# 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>Aqu铆 est谩n tus bullets:</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.")