from dotenv import load_dotenv import streamlit as st import os import google.generativeai as genai load_dotenv() genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) # Función para obtener respuesta del modelo Gemini def get_gemini_response(target_audience, product, action, mood, length): model = genai.GenerativeModel("gemini-1.5-flash") # Crear el prompt para el modelo full_prompt = f""" You are a skilled copywriter and storyteller. Create a persuasive story in Spanish following the P.A.S.A. formula (Problema, Agitación, Solución, Acción). Do not explicitly label or explain each section (Problema, Agitación, Solución, Acción). Instead, weave these elements naturally into a cohesive, flowing narrative that emotionally connects with the {target_audience}. The story should have {length} words, with a {mood} tone. Here are the details: 1. Problema: Describe a specific problem that keeps the {target_audience} awake at night. 2. Agitación: Amplify the emotional and practical consequences of this problem. 3. Solución: Highlight how the product '{product}' solves this problem and improves their life. 4. Acción: End with the call-to-action '{action}' to motivate the reader to take immediate steps. Write a cohesive, engaging, and emotionally resonant narrative tailored to connect with the {target_audience}. """ response = model.generate_content([full_prompt]) if response and response.parts: text = response.parts[0].text return text.strip() 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 P.A.S.A.", page_icon=":pencil:", layout="wide") st.markdown("

Generador de Historias P.A.S.A.

", unsafe_allow_html=True) st.markdown("

Crea historias persuasivas con inteligencia artificial, diseñadas para conectar emocionalmente con tu audiencia.

", unsafe_allow_html=True) # CSS personalizado para el botón st.markdown(""" """, unsafe_allow_html=True) # Crear las columnas para el diseño (40% para la izquierda, 60% para la derecha) col1, col2 = st.columns([2, 3]) # Entradas del usuario en la columna izquierda (col1) with col1: target_audience = st.text_input("Público objetivo", placeholder="¿A quién está dirigido tu mensaje?") product = st.text_input("Producto/Servicio", placeholder="¿Qué estás ofreciendo?") action = st.text_area("Llamado a la acción", "¿Qué acción específica debe tomar tu audiencia?") # Personalización adicional with st.expander("Personaliza tu historia"): mood = st.selectbox("Tono de la historia:", ["Emocional", "Triste", "Feliz", "Horror", "Comedia", "Romántico"]) length = st.slider("Longitud de la historia (palabras):", min_value=50, max_value=200, value=150, step=10) # Botón para generar contenido submit = st.button("Generar mi historia") # Mostrar el contenido generado en la columna derecha (col2) with col2: if submit: if target_audience and product and action: try: response = get_gemini_response(target_audience, product, action, mood, length) st.subheader("Historia generada:") st.write(response) except ValueError as e: st.error(f"Error: {str(e)}") else: st.error("Por favor, completa todos los campos requeridos (Público objetivo, Producto y Acción).")