File size: 3,799 Bytes
91a0d7e
a8fd769
 
 
d51e47b
 
 
a8fd769
d51e47b
1ff0df4
e8314b4
 
a8fd769
e8314b4
1ff0df4
e8314b4
 
 
 
 
 
 
 
 
1ff0df4
 
a8fd769
ff360f5
e8314b4
a8fd769
1ff0df4
d51e47b
1ff0df4
e8314b4
d51e47b
e8314b4
 
bef3dc5
e8314b4
a8fd769
 
 
e8314b4
 
a8fd769
 
 
e8314b4
 
 
a8fd769
 
e8314b4
a8fd769
 
e8314b4
 
a8fd769
 
 
 
03cdd46
 
dc809d3
03cdd46
 
 
 
 
a8fd769
03cdd46
 
 
 
60ce54c
03cdd46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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). 
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("<h1 style='text-align: center;'>Generador de Historias P.A.S.A.</h1>", unsafe_allow_html=True)
st.markdown("<h3 style='text-align: center;'>Crea historias persuasivas con inteligencia artificial, dise帽adas para conectar emocionalmente con tu audiencia.</h3>", unsafe_allow_html=True)

# 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 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=500, value=200, 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).")