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, 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 without mentioning the product directly. 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.'. """ # 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 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: * Good and Bad: 'The bathroom cabinet is the best place to store medicine, right? Incorrect. It's the worst. The facts are on page 10.' * The Best/The Worst: 'The best verb tense that gives your clients the feeling they've already bought from you.' * Stories: 'The story of...', 'The mysteries of...', 'The legend of...' * Trick: 'A simple system to write copy without trying to convince them to buy.' * The Truth: 'The truth that you've never been told in school, or at home, about how to make a living from music.' * Asking a Question: 'Did you know that...' * When: '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.' Feel free to include a mention of {product_mention} where appropriate. """ 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("
{generated_bullets}